Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parser error #4

Open
josdejong opened this issue Sep 18, 2014 · 4 comments
Open

Parser error #4

josdejong opened this issue Sep 18, 2014 · 4 comments

Comments

@josdejong
Copy link

Thanks for this library, I really like this solution where you can provide a query as string.

In the docs I see this example:

var query = $objeq("'^Ro' =~ name -> name + ' is ' + age"); // OK

which works fine. However, turning around property and value in the comparison does not work:

var query = $objeq("name ~= '^Ro' -> name + ' is ' + age"); // ERROR
@kode4food
Copy link
Contributor

Please see: The Language Reference

This was done intentionally (a deviation from Ruby) because Objeq isn't parsing the Regular Expressions as part of its lexing pass. Instead, it's just taking the string (or expression result) and constructing a new RegExp instance from it. Because of this, there's no way to disambiguate a string from a Regex, and therefore the ordering is necessary.

@josdejong
Copy link
Author

ah I understand. That's a pity, name ~= '^Ro' feels much more natural to me :(.

Maybe you could add support for regexp notation like JavaScript has, like:

var query = $objeq("name ~= /^Ro/ -> name + ' is ' + age");

Thanks for your fast reply.

@kode4food
Copy link
Contributor

Though the reverse ~= operator isn't part of Ruby as far as I know, it has a certain aesthetic appeal to it that I very much like. Lexing regular expressions might be a huge pain in the ass, but it's worth a shot.

@josdejong
Copy link
Author

Yes, this ~= operator is nice. I thought though the that its meaning was "about equal", which makes sense too in the context of a regexp.

You may not need to do any lexing for the regular expressions at all, just interpret the contents between the forward slashes like a string and feed it to a new RegExp(...).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants