lark-parser / Lark.js

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

Unable to get the parsed tree data when statement is incomplete #32

Closed jillyj closed 2 years ago

jillyj commented 2 years ago

Generated parser: kestrelParser.zip

Code

function handle_errors(e) { return true; }

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

Expected: can get treeData after parsing even if the statement is incomplete.

erezsh commented 2 years ago

Well, before parsing is complete, there is no single tree, but several fragments of trees.

You can find them in the instance of the parser state, ParserState.value_stack (https://github.com/lark-parser/lark/blob/master/lark/parsers/lalr_parser.py#L92).

If you have an idea on how to make an API out of that, let me know.

jillyj commented 2 years ago

Ok, I got it. I'll get the data from ParserState.value_stack. Thanks!

erezsh commented 2 years ago

Happy to help.