Support for comments in grammar langauge.
@@ -430,7 +430,9 @@ class Grammar(object):
RECOGNIZER,
ASSOC,
ASSOC_PRIOR,
- SEQUENCE) = [NonTerminal(name) for name in [
+ SEQUENCE,
+ LAYOUT,
+ LAYOUT_ITEM) = [NonTerminal(name) for name in [
'Grammar',
'ProductionSet',
'Production',
@@ -442,22 +444,28 @@ class Grammar(object):
'Recognizer',
'Assoc',
'AssocPrior',
- 'Sequence']]
+ 'Sequence',
+ 'LAYOUT',
+ 'LAYOUT_ITEM']]
(NAME,
STR_TERM,
REGEX_TERM,
- PRIOR) = [Terminal(name, RegExRecognizer(regex)) for name, regex in
+ PRIOR,
+ WS,
+ COMMENT) = [Terminal(name, RegExRecognizer(regex)) for name, regex in
[
('Name', r'[a-zA-Z0-9_]+'),
('StrTerm', r'''(?s)('[^'\\]*(?:\\.[^'\\]*)*')|'''
r'''("[^"\\]*(?:\\.[^"\\]*)*")'''),
('RegExTerm', r'''\/((\\/)|[^/])*\/'''),
- ('Prior', r'\d+')
+ ('Prior', r'\d+'),
+ ('WS', r'\s+'),
+ ('Comment', r'\/\/.*'),
]]
pg_productions = [
- [GRAMMAR, [PRODUCTION_SET]],
+ [GRAMMAR, [PRODUCTION_SET, EOF]],
[PRODUCTION_SET, [PRODUCTION_SET, PRODUCTION]],
[PRODUCTION_SET, [PRODUCTION_SET, TERM_PRODUCTION]],
[PRODUCTION_SET, [PRODUCTION]],
@@ -481,6 +489,13 @@ pg_productions = [
[GSYMBOL, [RECOGNIZER]],
[RECOGNIZER, [STR_TERM]],
[RECOGNIZER, [REGEX_TERM]],
+
+ # Support for comments,
+ [LAYOUT, [LAYOUT_ITEM]],
+ [LAYOUT, [LAYOUT, LAYOUT_ITEM]],
+ [LAYOUT_ITEM, [WS]],
+ [LAYOUT_ITEM, [COMMENT]],
+ [LAYOUT_ITEM, [EMPTY]],
]
