question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

StandAlone Parsers return different ASTs with same DSL input

See original GitHub issue
from python_parser import Lark_StandAlone

class PythonIndenter(Indenter):
    NL_type = '_NEWLINE'
    OPEN_PAREN_types = ['LPAR', 'LSQB', 'LBRACE']
    CLOSE_PAREN_types = ['RPAR', 'RSQB', 'RBRACE']
    INDENT_type = '_INDENT'
    DEDENT_type = '_DEDENT'
    tab_len = 8


simple_stmts = """
a=1
b=2

"""
kwargs = dict(postlex=PythonIndenter())

parser1 = Lark_StandAlone(**kwargs)
print(parser1.parse(simple_stmts))

parser2 = Lark_StandAlone(**kwargs)
print(parser2.parse(simple_stmts))

Two parsers are both instanced from Lark_StandAlone class and parse the same string, however, the results are two different ASTs shown as below, could you please check it for me? Thanks.

Tree(file_input, [Tree(expr_stmt, [Tree(var, [Token(NAME, 'a')]), Tree(number, [Token(DEC_NUMBER, '1')])]), Tree(expr_stmt, [Tree(var, [Token(NAME, 'b')]), Tree(number, [Token(DEC_NUMBER, '2')])])])

Tree(_cb4_NonTerminal('file_input'), [Tree(_cb448_NonTerminal('__anon_star_0'), [Tree(_cb448_NonTerminal('__anon_star_0'), [Tree(_cb447_NonTerminal('__anon_star_0'), [Token(_NEWLINE, '\n')]), Tree(_cb141_NonTerminal('stmt'), [Tree(_cb146_NonTerminal('simple_stmt'), [Tree(_cb150_NonTerminal('small_stmt'), [Tree(_cb157_NonTerminal('expr_stmt'), [Tree(_cb162_NonTerminal('testlist_star_expr'), [Tree(_cb263_NonTerminal('test'), [Tree(_cb272_NonTerminal('or_test'), [Tree(_cb274_NonTerminal('and_test'), [Tree(_cb277_NonTerminal('not_test'), [Tree(_cb278_NonTerminal('comparison'), [Tree(_cb281_NonTerminal('expr'), [Tree(_cb284_NonTerminal('xor_expr'), [Tree(_cb286_NonTerminal('and_expr'), [Tree(_cb287_NonTerminal('shift_expr'), [Tree(_cb289_NonTerminal('arith_expr'), [Tree(_cb292_NonTerminal('term'), [Tree(_cb293_NonTerminal('factor'), [Tree(_cb318_NonTerminal('power'), [Tree(_cb320_NonTerminal('await_expr'), [Tree(_cb323_NonTerminal('atom_expr'), [Tree(_cb338_NonTerminal('atom'), [Token(NAME, 'a')])])])])])])])])])])])])])])])])]), Tree(_cb463_NonTerminal('__anon_star_6'), [Token(EQUAL, '='), Tree(_cb162_NonTerminal('testlist_star_expr'), [Tree(_cb263_NonTerminal('test'), [Tree(_cb272_NonTerminal('or_test'), [Tree(_cb274_NonTerminal('and_test'), [Tree(_cb277_NonTerminal('not_test'), [Tree(_cb278_NonTerminal('comparison'), [Tree(_cb281_NonTerminal('expr'), [Tree(_cb284_NonTerminal('xor_expr'), [Tree(_cb286_NonTerminal('and_expr'), [Tree(_cb287_NonTerminal('shift_expr'), [Tree(_cb289_NonTerminal('arith_expr'), [Tree(_cb292_NonTerminal('term'), [Tree(_cb293_NonTerminal('factor'), [Tree(_cb318_NonTerminal('power'), [Tree(_cb320_NonTerminal('await_expr'), [Tree(_cb323_NonTerminal('atom_expr'), [Tree(_cb340_NonTerminal('atom'), [Tree(_cb440_NonTerminal('number'), [Token(DEC_NUMBER, '1')])])])])])])])])])])])])])])])])])])])])]), Token(_NEWLINE, '\n')])])]), Tree(_cb141_NonTerminal('stmt'), [Tree(_cb146_NonTerminal('simple_stmt'), [Tree(_cb150_NonTerminal('small_stmt'), [Tree(_cb157_NonTerminal('expr_stmt'), [Tree(_cb162_NonTerminal('testlist_star_expr'), [Tree(_cb263_NonTerminal('test'), [Tree(_cb272_NonTerminal('or_test'), [Tree(_cb274_NonTerminal('and_test'), [Tree(_cb277_NonTerminal('not_test'), [Tree(_cb278_NonTerminal('comparison'), [Tree(_cb281_NonTerminal('expr'), [Tree(_cb284_NonTerminal('xor_expr'), [Tree(_cb286_NonTerminal('and_expr'), [Tree(_cb287_NonTerminal('shift_expr'), [Tree(_cb289_NonTerminal('arith_expr'), [Tree(_cb292_NonTerminal('term'), [Tree(_cb293_NonTerminal('factor'), [Tree(_cb318_NonTerminal('power'), [Tree(_cb320_NonTerminal('await_expr'), [Tree(_cb323_NonTerminal('atom_expr'), [Tree(_cb338_NonTerminal('atom'), [Token(NAME, 'b')])])])])])])])])])])])])])])])])]), Tree(_cb463_NonTerminal('__anon_star_6'), [Token(EQUAL, '='), Tree(_cb162_NonTerminal('testlist_star_expr'), [Tree(_cb263_NonTerminal('test'), [Tree(_cb272_NonTerminal('or_test'), [Tree(_cb274_NonTerminal('and_test'), [Tree(_cb277_NonTerminal('not_test'), [Tree(_cb278_NonTerminal('comparison'), [Tree(_cb281_NonTerminal('expr'), [Tree(_cb284_NonTerminal('xor_expr'), [Tree(_cb286_NonTerminal('and_expr'), [Tree(_cb287_NonTerminal('shift_expr'), [Tree(_cb289_NonTerminal('arith_expr'), [Tree(_cb292_NonTerminal('term'), [Tree(_cb293_NonTerminal('factor'), [Tree(_cb318_NonTerminal('power'), [Tree(_cb320_NonTerminal('await_expr'), [Tree(_cb323_NonTerminal('atom_expr'), [Tree(_cb340_NonTerminal('atom'), [Tree(_cb440_NonTerminal('number'), [Token(DEC_NUMBER, '2')])])])])])])])])])])])])])])])])])])])])]), Token(_NEWLINE, '\n\n')])])])])

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
simplelife963commented, Apr 23, 2019

The parsing results are now consistent by using the latest codes on master. We really appreciated your work, Erezsh!

1reaction
simplelife963commented, Apr 10, 2019

I re-generated the stand-alone parser by using the latest commit on master and it solved my problem and works perfectly. Really appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Building fast interpreters in Rust - The Cloudflare Blog
When building a custom Domain Specific Language (DSL), the first thing we need to be able to do is parse it. This should...
Read more >
Parsing in Java: all the tools and libraries you can use
We present and compare all possible alternatives you can use to parse languages in Java. From libraries to parser generators, we present all...
Read more >
Understanding the Clang AST - Jonas Devlieghere
The AST Matcher Reference explains you how to use the DSL to build matchers for the nodes you're interested in. A MatchCallback is...
Read more >
2013 - Red Programming Language
Limited backtracking: only input and rules positions are backtracked, other changes remain. Two modes: string-parsing (for example: external DSL) ...
Read more >
Efficient parsing with parser combinators - ScienceDirect.com
All the parser combinators share the same interface, Image 30 . The Image 31 parameter provides access to the input stream and to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found