[4082] | 1 | # To maximize python3/python2 compatibility |
---|
| 2 | from __future__ import print_function |
---|
| 3 | from __future__ import unicode_literals |
---|
| 4 | from __future__ import division |
---|
| 5 | from __future__ import absolute_import |
---|
| 6 | |
---|
| 7 | # |
---|
| 8 | # helper code: we define our match tokens |
---|
| 9 | lastval = '' |
---|
| 10 | def monitor(location,value): |
---|
| 11 | global lastval |
---|
| 12 | #print 'At %s: %s' % (location,repr(value)) |
---|
| 13 | lastval = repr(value) |
---|
| 14 | return value |
---|
| 15 | |
---|
| 16 | |
---|
| 17 | # Begin -- grammar generated by Yapps |
---|
| 18 | import sys, re |
---|
| 19 | from . import yapps3_compiled_rt as yappsrt |
---|
| 20 | |
---|
| 21 | class TypeParserScanner(yappsrt.Scanner): |
---|
| 22 | def __init__(self, *args,**kwargs): |
---|
| 23 | patterns = [ |
---|
| 24 | ('([ \t\n\r])', '([ \t\n\r])'), |
---|
| 25 | ('container', '[A-Za-z]+\\('), |
---|
| 26 | ('identifier', '[A-Za-z]+'), |
---|
| 27 | ('c_c_b', '\\)'), |
---|
| 28 | ('o_c_b', '\\('), |
---|
| 29 | ('comma', '\\,'), |
---|
| 30 | ('END', '$'), |
---|
| 31 | ] |
---|
| 32 | yappsrt.Scanner.__init__(self,patterns,['([ \t\n\r])'],*args,**kwargs) |
---|
| 33 | |
---|
| 34 | class TypeParser(yappsrt.Parser): |
---|
| 35 | Context = yappsrt.Context |
---|
| 36 | def input(self, _parent=None): |
---|
| 37 | _context = self.Context(_parent, self._scanner, self._pos, 'input', []) |
---|
| 38 | base_element = self.base_element(_context) |
---|
| 39 | p = [base_element] |
---|
| 40 | while self._peek('END', 'comma') == 'comma': |
---|
| 41 | comma = self._scan('comma') |
---|
| 42 | base_element = self.base_element(_context) |
---|
| 43 | p.append(base_element) |
---|
| 44 | if self._peek() not in ['END', 'comma']: |
---|
| 45 | raise yappsrt.SyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['comma', 'END'])) |
---|
| 46 | END = self._scan('END') |
---|
| 47 | if len(p)==1: p = p[0] |
---|
| 48 | return p |
---|
| 49 | |
---|
| 50 | def base_element(self, _parent=None): |
---|
| 51 | _context = self.Context(_parent, self._scanner, self._pos, 'base_element', []) |
---|
| 52 | _token = self._peek('container', 'identifier') |
---|
| 53 | if _token == 'container': |
---|
| 54 | container = self._scan('container') |
---|
| 55 | element_list = self.element_list(_context) |
---|
| 56 | c_c_b = self._scan('c_c_b') |
---|
| 57 | return element_list |
---|
| 58 | else: # == 'identifier' |
---|
| 59 | identifier = self._scan('identifier') |
---|
| 60 | return identifier |
---|
| 61 | |
---|
| 62 | def element_list(self, _parent=None): |
---|
| 63 | _context = self.Context(_parent, self._scanner, self._pos, 'element_list', []) |
---|
| 64 | base_element = self.base_element(_context) |
---|
| 65 | p = [base_element] |
---|
| 66 | while self._peek('comma', 'c_c_b') == 'comma': |
---|
| 67 | comma = self._scan('comma') |
---|
| 68 | base_element = self.base_element(_context) |
---|
| 69 | p.append(base_element) |
---|
| 70 | if self._peek() not in ['comma', 'c_c_b']: |
---|
| 71 | raise yappsrt.SyntaxError(charpos=self._scanner.get_prev_char_pos(), context=_context, msg='Need one of ' + ', '.join(['comma', 'c_c_b'])) |
---|
| 72 | return p |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | def parse(rule, text): |
---|
| 76 | P = TypeParser(TypeParserScanner(text)) |
---|
| 77 | return yappsrt.wrap_error_reporter(P, rule) |
---|
| 78 | |
---|
| 79 | # End -- grammar generated by Yapps |
---|
| 80 | |
---|
| 81 | |
---|
| 82 | |
---|