declaresub / abnf

Python parser generator for ABNF grammars
MIT License
41 stars 9 forks source link

Unexpected `IndexError` on a grammar #14

Closed mristin closed 2 years ago

mristin commented 2 years ago

Hi, An issue https://github.com/aas-core-works/abnf-to-regexp/issues/26 has been raised for our tool, abnf-to-regexp, which I think that might be due to the bug in this module.

Namely, the attached grammar, grammar.abnf.txt raises an IndexError whereas I'd expected a parsing error.

Do you have any pointers about what to do with this issue?

mristin commented 2 years ago

Here is a short code snippet for you to reproduce the issue:

import pathlib

import abnf

text = pathlib.Path("grammar.abnf.txt").read_text()
text = text.replace("\r", "")

if not text.endswith("\n"):
    text = text + "\n"

text = text.replace("\n", "\r\n")

class OurRule(abnf.Rule):
    """Represent our ABNF rule list read from a file."""

    pass

node = abnf.parser.ABNFGrammarRule("rulelist").parse_all(text)
visitor = abnf.parser.ABNFGrammarNodeVisitor(rule_cls=OurRule)
visitor.visit(node)
declaresub commented 2 years ago

You have found a bug in CharValNodeVisitor that resulted in the node generated by parsing the quoted string '""' being read incorrectly. I will push out a fix soon.

declaresub commented 2 years ago

This is fixed in https://github.com/declaresub/abnf/commit/d40d9659b067191d5d29117b24e1dc218645a087. Thanks for breaking my code.

mristin commented 2 years ago

@declaresub thanks for the fix! Do you plan to release a patch version soon?

declaresub commented 2 years ago

Sure; I will do it now.

declaresub commented 2 years ago

ABNF 2.0.1 is now up at pypi.

mristin commented 2 years ago

@declaresub thanks a lot!