Lark.js icon indicating copy to clipboard operation
Lark.js copied to clipboard

SyntaxError: Invalid regular expression returned when parsing

Open jillyj opened this issue 3 years ago • 11 comments

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 avatar Mar 24 '22 03:03 jillyj

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

jillyj avatar Apr 11 '22 01:04 jillyj

Sorry, I had a few busy weeks.

I'll give it a look.

erezsh avatar Apr 11 '22 07:04 erezsh

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)

erezsh avatar Apr 11 '22 07:04 erezsh

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

jillyj avatar Apr 11 '22 07:04 jillyj

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)

jillyj avatar Apr 13 '22 01:04 jillyj

No... edit the grammar!

erezsh avatar Apr 13 '22 06:04 erezsh

Got it. Thanks! Let me try.

jillyj avatar Apr 13 '22 06:04 jillyj

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

jillyj avatar Apr 13 '22 06:04 jillyj

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.

erezsh avatar Apr 13 '22 06:04 erezsh

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

jillyj avatar Apr 15 '22 03:04 jillyj

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

erezsh avatar Apr 19 '22 09:04 erezsh