- @graken()
- def _name_(self):
- self._pattern(r'[a-z][a-z0-9_]+')
-
- @graken()
- def _and_op_(self):
- with self._choice():
- with self._option():
- self._token('&')
- with self._option():
- self._token('&&')
- with self._option():
- self._token('AND')
- with self._option():
- self._token('and')
- self._error('expecting one of: & && AND and')
-
- @graken()
- def _or_op_(self):
- with self._choice():
- with self._option():
- self._token('|')
- with self._option():
- self._token('||')
- with self._option():
- self._token('OR')
- with self._option():
- self._token('or')
- self._error('expecting one of: OR or | ||')
-
- @graken()
- def _not_op_(self):
- with self._choice():
- with self._option():
- self._token('!')
- with self._option():
- self._token('NOT')
- with self._option():
- self._token('not')
- self._error('expecting one of: ! NOT not')
-
-
-class TagsSemantics(object):
- def start(self, ast):
- return ast
-
- def expression(self, ast):
- return ast
-
- def expression_parens(self, ast):
- return ast
-
- def name(self, ast):
- return ast
-
- def and_op(self, ast):
- return ast
-
- def or_op(self, ast):
- return ast
-
- def not_op(self, ast):
- return ast
-
-
-def main(
- filename,
- startrule,
- trace=False,
- whitespace=None,
- nameguard=None,
- comments_re=None,
- eol_comments_re=None,
- ignorecase=None,
- left_recursion=True,
- **kwargs):
-
- with open(filename) as f:
- text = f.read()
- whitespace = whitespace or None
- parser = TagsParser(parseinfo=False)
- ast = parser.parse(
- text,
- startrule,
- filename=filename,
- trace=trace,
- whitespace=whitespace,
- nameguard=nameguard,
- ignorecase=ignorecase,
- **kwargs)
- return ast