Commit c2ff22b3 authored by eckhart's avatar eckhart
Browse files

parser.py: Grammar.as_ebnf(): warning message about missing directives and...

parser.py: Grammar.as_ebnf(): warning message about missing directives and possible abbreviations added
parent d31c8056
......@@ -1320,11 +1320,16 @@ class Grammar:
def as_ebnf(self) -> str:
"""
Serializes the Grammar object as a grammar-description in the
Extended Backus-Naur-Form. Does not serialize directives!
Extended Backus-Naur-Form. Does not serialize directives and
may contain abbreviations with three dots " ... " for very long
expressions.
"""
ebnf = ['# This grammar does not include any of the DHParser-specific ',
'# directives and may contain abbreviations ("...")!', '']
for entry, parser in self.__dict__.items():
if isinstance(parser, Parser) and sane_parser_name(entry):
ebnf.append(str(parser))
ebnf.append('')
return '\n'.join(ebnf)
......
......@@ -50,6 +50,7 @@ class TestWhitespace:
def test_non_empty_derivation(self):
pass
class TestParserError:
def test_parser_error_str(self):
pe = ParserError(Node('TAG', 'test').with_pos(0), StringView('Beispiel'), None, True)
......@@ -475,7 +476,8 @@ class TestSeries:
def test_ebnf_serialization(self):
ebnf_grammar = get_ebnf_grammar()
# TODO: Add test here
# print(ebnf_grammar.as_ebnf())
ebnf = ebnf_grammar.as_ebnf()
print(ebnf)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment