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

Bug: Unexpected ParserError #233

Open
spacemanspiff2007 opened this issue Jun 30, 2023 · 1 comment
Open

Bug: Unexpected ParserError #233

spacemanspiff2007 opened this issue Jun 30, 2023 · 1 comment

Comments

@spacemanspiff2007
Copy link

spacemanspiff2007 commented Jun 30, 2023

I hope you don't mind that I ask another about grammar but I'm stuck and the error makes no sense to me.

Example to reproduce

from parsimonious.grammar import Grammar

grammar = Grammar(r""" 
    properties_def   = "[" ws? properties_comma? "]" ws?
    properties_comma = property_def ("," ws? property_def)*
    property_def     = id ws? "=" ws? property_value ws?
    property_value   = bool / number / string

    # Primitives
    bool   = "true" / "false"
    number = ~r'-?\d*(\.\d+)?'
    string = ~r'"[^"]*"' / ~r"'[^']*'" 
    id     = ~r'\w[\w-]*'
    ws     = ~r"\s+"
   """)


properties_str = 'profile="system:hysteresis",lower="29 °C",upper="30 °C"'

# this works
grammar['properties_comma'].match(properties_str)

# parsimonious.exceptions.ParseError: Rule 'ws' didn't match at '"system:hysteresis",' (line 1, column 10).
grammar['properties_def'].match('[' + properties_str + ']')

This works:

grammar['properties_comma'].match('profile="system:hysteresis",lower="29 °C",upper="30 °C"')

This throws an error:

grammar['properties_def'].match('[profile="system:hysteresis",lower="29 °C",upper="30 °C"]')
parsimonious.exceptions.ParseError: Rule 'ws' didn't match at '"system:hysteresis",' (line 1, column 10).

This seems to be the faulty rule:

"[" ws? properties_comma? "]" ws?

which does not match

'[' + properties_str + ']'

However I marked both ws rules as optional so the ParseError makes no sense.
Do you have any idea why this ws error is raised?

Thank you for your help!

@spacemanspiff2007 spacemanspiff2007 changed the title Unexpected ParserError Bug: Unexpected ParserError Jul 13, 2023
@spacemanspiff2007
Copy link
Author

Another PEG parser does not throw the error with the same rule so this is most likely a bug

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

No branches or pull requests

1 participant