grasp icon indicating copy to clipboard operation
grasp copied to clipboard

Question: How to escape dollar sign?

Open Ventzy opened this issue 8 years ago • 5 comments

I want to match this js code:

$stateProvider.state('stateName', {})

And if I do this in equery '$stateProvider.state(,)' - $stateProvider is actually named match in equery, so it will match "ANYSTRING.state('stateName', {})". I have tried to esacape it with $stateProvider or with $$stateProvider, but they don't work.

Ventzy avatar Jul 23 '15 21:07 Ventzy

There is no way to do so currently using equery, you can do it some of it with squery:

grasp 'call[callee=member[obj=#$stateProvider][prop=#state]]'

gkz avatar Jul 23 '15 22:07 gkz

With squery am I losing ability to have named matches? I want to use them like matching the first parameter '$stateProvider.state($name,__)'

Ventzy avatar Jul 24 '15 05:07 Ventzy

I have made a little patch in grasp-equery/parse.js and it works for my example above with $$stateProvider. I don't know would it work in more complex query as I don't know grasp-equery internals. Here it is:

  function processNode(node){
      ...    
      } else if (that = /^_\$(\w*)$/.exec(name)) {
        ...

      >>> my addition >>>
      } else if (that = /^\$\$(\w+)$/.exec(name)) {
        node.name = node.name.substr(1);
        return;
      <<< my addition <<<

      } else if (that = /^\$(\w+)$/.exec(name)) {
      ....

Ventzy avatar Jul 24 '15 05:07 Ventzy

@gkz Hi, I'd like to confirm with you that not only dollar sign, but even underscore is not really available for lookup with equery, is it not?

kubijo avatar Aug 15 '15 21:08 kubijo

A single underscore should work

gkz avatar Aug 17 '15 19:08 gkz