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

Unexpected NoMatch when suppressing a StrMatch from the parse tree #98

Closed
vpavlu opened this issue Mar 23, 2023 · 1 comment
Closed
Labels

Comments

@vpavlu
Copy link

vpavlu commented Mar 23, 2023

Hi! I have a grammar where newlines matter but I don't want the newlines to be part of the parse tree. Tried to suppress the newlines using http://textx.github.io/Arpeggio/2.0/parse_trees/#suppressing-parse-tree-nodes but hit a wall.

Here's my reduced example:

from arpeggio import ZeroOrMore, RegExMatch, StrMatch, EOF
from arpeggio import ParserPython

class SuppressStrMatch(StrMatch):
    suppress = True


#newline = StrMatch('\n')         # with this i get a successful parse
newline = SuppressStrMatch('\n')  # with this i get a NoMatch at (3, 1)

def line():                    return RegExMatch(r'^.*$'), newline

def grammar():                 return ZeroOrMore(line), EOF



parser = ParserPython(grammar, debug=True, skipws=False)
result = parser.parse('one\n\nthree\nfour\n')
print(result.tree_str())

Running this with 'Arpeggio==2.0.0' gives me arpeggio.NoMatch: Expected EOF at position (3, 1) => 'one\n\n*three\nfour'. When I use newline = StrMatch('\n') instead of the suppressed newline = SuppressStrMatch('\n') the input is parsed with success. Seems to be a problem with suppress altering parser behaviour?

@igordejanovic
Copy link
Member

Thanks for the report and the reduced example. I confirm that it is a bug. At first glance it seems that it is a bad interplay between the ZeroOrMore rule and suppressed match. Zero or more thinks that the suppressed rule match is not successful and tries to continue by matching EOF.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants