lark-parser / Lark.js

Live port of Lark's standalone parser to Javascript
MIT License
71 stars 12 forks source link

Incorrect line info returned when error occurs #23

Closed jillyj closed 2 years ago

jillyj commented 2 years ago

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

Code to parse string disp a\nproc2 = get. The 1st line disp a is valid string. The 2nd line proc2=get is invalid and should return error. However, the exception I got from parser told me the error occurs at line 1. I checked the parser, and it uses \n as newline char, so it should return line 2 has error.

function handle_errors(e) { return true; }

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

Expected: the exception should return correct line number where the error occurs.

jillyj commented 2 years ago

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

erezsh commented 2 years ago

Fixed in master

jillyj commented 2 years ago

The fix works. Thank you!

erezsh commented 2 years ago

Happy to help