Commit d0c5b0fd authored by Eckhart Arnold's avatar Eckhart Arnold
Browse files

- beautification

parent 189ce20e
...@@ -190,38 +190,31 @@ class EBNFGrammar(Grammar): ...@@ -190,38 +190,31 @@ class EBNFGrammar(Grammar):
""" """
expression = Forward() expression = Forward()
source_hash__ = "a131abc5259738631000cda90d2fc65b" source_hash__ = "a131abc5259738631000cda90d2fc65b"
parser_initialization__ = "upon instantiation" tialization__ = "upon instantiation"
COMMENT__ = r'#.*(?:\n|$)' COMMENT__ = r'#.*(?:\n|$)'
WHITESPACE__ = r'\s*' WHITESPACE__ = r'\s*'
WSP__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__) WSP__ = mixin_comment(whitespace=WHITESPACE__, comment=COMMENT__)
wspL__ = '' wspL__ = ''
wspR__ = WSP__ wspR__ = WSP__
EOF = NegativeLookahead(RegExp('.')) EOF = NegativeLookahead(RegExp('.'))
list_ = Series(RE('\\w+'), ZeroOrMore(Series(Token(","), RE('\\w+'), mandatory=1000)), list_ = Series(RE('\\w+'), ZeroOrMore(Series(Token(","), RE('\\w+'))))
mandatory=1000)
regexp = RE('~?/(?:\\\\/|[^/])*?/~?') regexp = RE('~?/(?:\\\\/|[^/])*?/~?')
literal = Alternative(RE('"(?:[^"]|\\\\")*?"'), RE("'(?:[^']|\\\\')*?'")) literal = Alternative(RE('"(?:[^"]|\\\\")*?"'), RE("'(?:[^']|\\\\')*?'"))
symbol = RE('(?!\\d)\\w+') symbol = RE('(?!\\d)\\w+')
option = Series(Token("["), expression, Token("]"), mandatory=2) option = Series(Token("["), expression, Token("]"), mandatory=2)
repetition = Series(Token("{"), expression, Token("}"), mandatory=2) repetition = Series(Token("{"), expression, Token("}"), mandatory=2)
oneormore = Series(Token("{"), expression, Token("}+"), mandatory=1000) oneormore = Series(Token("{"), expression, Token("}+"))
group = Series(Token("("), expression, Token(")"), mandatory=2) group = Series(Token("("), expression, Token(")"), mandatory=2)
retrieveop = Alternative(Token("::"), Token(":")) retrieveop = Alternative(Token("::"), Token(":"))
flowmarker = Alternative(Token("!"), Token("&"), Token("-!"), Token("-&")) flowmarker = Alternative(Token("!"), Token("&"), Token("-!"), Token("-&"))
factor = Alternative( factor = Alternative(Series(Option(flowmarker), Option(retrieveop), symbol, NegativeLookahead(Token("="))),
Series(Option(flowmarker), Option(retrieveop), symbol, NegativeLookahead(Token("=")), Series(Option(flowmarker), literal), Series(Option(flowmarker), regexp),
mandatory=1000), Series(Option(flowmarker), literal, mandatory=1000), Series(Option(flowmarker), group), Series(Option(flowmarker), oneormore), repetition, option)
Series(Option(flowmarker), regexp, mandatory=1000), term = OneOrMore(Series(Option(Token("§")), factor))
Series(Option(flowmarker), group, mandatory=1000), expression.set(Series(term, ZeroOrMore(Series(Token("|"), term))))
Series(Option(flowmarker), oneormore, mandatory=1000), repetition, option) directive = Series(Token("@"), symbol, Token("="), Alternative(regexp, literal, list_), mandatory=1)
term = OneOrMore(Series(Option(Token("§")), factor, mandatory=1000))
expression.set(
Series(term, ZeroOrMore(Series(Token("|"), term, mandatory=1000)), mandatory=1000))
directive = Series(Token("@"), symbol, Token("="), Alternative(regexp, literal, list_),
mandatory=1)
definition = Series(symbol, Token("="), expression, mandatory=1) definition = Series(symbol, Token("="), expression, mandatory=1)
syntax = Series(Option(RE('', wR='', wL=WSP__)), ZeroOrMore(Alternative(definition, directive)), syntax = Series(Option(RE('', wR='', wL=WSP__)), ZeroOrMore(Alternative(definition, directive)), EOF, mandatory=2)
EOF, mandatory=2)
root__ = syntax root__ = syntax
......
...@@ -165,6 +165,7 @@ class HistoryRecord: ...@@ -165,6 +165,7 @@ class HistoryRecord:
self.line_col = (1, 1) # type: Tuple[int, int] self.line_col = (1, 1) # type: Tuple[int, int]
if call_stack: if call_stack:
document = call_stack[-1].grammar.document__.text document = call_stack[-1].grammar.document__.text
# TODO: Use lbreaks instead of document here
self.line_col = line_col(document, len(document) - remaining) self.line_col = line_col(document, len(document) - remaining)
def __str__(self): def __str__(self):
......
Markdown is supported
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