2 # -*- coding: utf-8 -*-
6 # This file was automatically generated by Grako.
8 # https://pypi.python.org/pypi/grako/
10 # Any changes you make to it will be overwritten the next time
11 # the file is generated.
14 from __future__ import print_function, division, absolute_import, unicode_literals
16 from grako.parsing import graken, Parser
17 from grako.util import re, RE_FLAGS, generic_main # noqa
20 __version__ = (2016, 7, 10, 22, 31, 57, 6)
31 class TagsParser(Parser):
42 super(TagsParser, self).__init__(
43 whitespace=whitespace,
45 comments_re=comments_re,
46 eol_comments_re=eol_comments_re,
47 ignorecase=ignorecase,
48 left_recursion=left_recursion,
60 def _expression_(self):
68 self._or_expression_()
69 self._error('no available options')
72 def _or_expression_(self):
78 def _and_expression_(self):
84 def _not_expression_(self):
89 def _parens_expression_(self):
95 def _expression1_(self):
103 self._and_expression_()
104 self._error('no available options')
107 def _expression2_(self):
115 self._not_expression_()
116 self._error('no available options')
119 def _expression3_(self):
122 self._parens_expression_()
125 self._error('no available options')
138 self._error('expecting one of: & && AND and')
151 self._error('expecting one of: OR or | ||')
162 self._error('expecting one of: ! NOT not')
166 self._pattern(r'[a-z][a-z0-9_]+')
169 class TagsSemantics(object):
170 def start(self, ast):
173 def expression(self, ast):
176 def or_expression(self, ast):
179 def and_expression(self, ast):
182 def not_expression(self, ast):
185 def parens_expression(self, ast):
188 def expression1(self, ast):
191 def expression2(self, ast):
194 def expression3(self, ast):
197 def and_op(self, ast):
200 def or_op(self, ast):
203 def not_op(self, ast):
217 eol_comments_re=None,
222 with open(filename) as f:
224 whitespace = whitespace or None
225 parser = TagsParser(parseinfo=False)
231 whitespace=whitespace,
233 ignorecase=ignorecase,
237 if __name__ == '__main__':
239 ast = generic_main(main, TagsParser, name='Tags')
244 print(json.dumps(ast, indent=2))