- @graken()
- def _and_expression_(self):
- self._expression2_()
- self._and_op_()
- self._expression1_()
-
- @graken()
- def _not_expression_(self):
- self._not_op_()
- self._expression3_()
-
- @graken()
- def _parens_expression_(self):
- self._token('(')
- self._expression_()
- self._token(')')
-
- @graken()
- def _expression1_(self):
- with self._choice():
- with self._option():
- self._expression2_()
- with self._ifnot():
- self._and_op_()
- with self._option():
- self._and_expression_()
- self._error('no available options')
-
- @graken()
- def _expression2_(self):
- with self._choice():
- with self._option():
- with self._ifnot():
- self._not_op_()
- self._expression3_()
- with self._option():
- self._not_expression_()
- self._error('no available options')
-
- @graken()
- def _expression3_(self):
- with self._choice():
- with self._option():
- self._parens_expression_()
- with self._option():
- self._name_()
- self._error('no available options')
-
- @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')
-
- @graken()
- def _name_(self):
- self._pattern(r'[a-z][a-z0-9_]+')
-
-
-class TagsSemantics(object):
- def start(self, ast):
- return ast
-
- def expression(self, ast):
- return ast
-
- def or_expression(self, ast):
- return ast
-
- def and_expression(self, ast):
- return ast
-
- def not_expression(self, ast):
- return ast
-
- def parens_expression(self, ast):
- return ast
-
- def expression1(self, ast):
- return ast
-
- def expression2(self, ast):
- return ast
-
- def expression3(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 name(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