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

SyntaxError: Invalid regular expression returned when parsing #21

Open
jillyj opened this issue Mar 24, 2022 · 11 comments
Open

SyntaxError: Invalid regular expression returned when parsing #21

jillyj opened this issue Mar 24, 2022 · 11 comments
Labels
bug Something isn't working

Comments

@jillyj
Copy link
Contributor

jillyj commented Mar 24, 2022

Grammar file: https://github.com/opencybersecurityalliance/kestrel-lang/blob/develop/src/kestrel/syntax/kestrel.lark
Generated parser:
kestrelParser.js.zip

When parsing this statement procs2 = GET process abc, the parser throws the exception like below which is not caught by parser.
image

Code

function handle_errors(e) { return true; }

  try {
    treeData = parser.parse(text, null, handle_errors).children[0];
  } catch (e) {
    console.debug("uncaught error:", e)
  }

Expected:
This kind of error can be handled by the parser, so we can get the parsing tree and the error info like Unexpected character or Unexpected Token.

@jillyj
Copy link
Contributor Author

jillyj commented Apr 11, 2022

@erezsh could you please take a look at this issue?

@erezsh
Copy link
Member

erezsh commented Apr 11, 2022

Sorry, I had a few busy weeks.

I'll give it a look.

@erezsh erezsh added the bug Something isn't working label Apr 11, 2022
@erezsh
Copy link
Member

erezsh commented Apr 11, 2022

This happens because Javascript's regex implementation doesn't support all the features that Python has.

This might take a bit longer to fix.

Meanwhile, a possible work around is to change

FUNCNAME: (MIN|MAX|SUM|AVG|COUNT|NUNIQUE)

to

funcname: (MIN|MAX|SUM|AVG|COUNT|NUNIQUE)

@jillyj
Copy link
Contributor Author

jillyj commented Apr 11, 2022

Thank you for the response. Looking forward to your fix. :)

@jillyj
Copy link
Contributor Author

jillyj commented Apr 13, 2022

This happens because Javascript's regex implementation doesn't support all the features that Python has.

This might take a bit longer to fix.

Meanwhile, a possible work around is to change

FUNCNAME: (MIN|MAX|SUM|AVG|COUNT|NUNIQUE)

to

funcname: (MIN|MAX|SUM|AVG|COUNT|NUNIQUE)

Do you mean to edit the generated parser.js? However, I could not find the string.

 FUNCNAME: (MIN|MAX|SUM|AVG|COUNT|NUNIQUE)

@erezsh
Copy link
Member

erezsh commented Apr 13, 2022

No... edit the grammar!

@jillyj
Copy link
Contributor Author

jillyj commented Apr 13, 2022

Got it. Thanks! Let me try.

@jillyj
Copy link
Contributor Author

jillyj commented Apr 13, 2022

yeah, updating the grammar from FUNCNAME to funcname works. Looking forward to your fix. :)

@erezsh
Copy link
Member

erezsh commented Apr 13, 2022

The "fix" is most likely going to be preventing users from doing what you were trying to do and throwing an error instead.

I don't know if there is a way to make it work in Javascript. At least, without implementing part of the regex mechanism myself.

@jillyj
Copy link
Contributor Author

jillyj commented Apr 15, 2022

I got it. Thanks. Would you mind to release a version which contains other fixes first?

@erezsh
Copy link
Member

erezsh commented Apr 19, 2022

Released https://github.com/lark-parser/Lark.js/releases/tag/0.1.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants