| OLD | NEW |
| 1 # Copyright 2013 the V8 project authors. All rights reserved. | 1 # Copyright 2013 the V8 project authors. All rights reserved. |
| 2 # Redistribution and use in source and binary forms, with or without | 2 # Redistribution and use in source and binary forms, with or without |
| 3 # modification, are permitted provided that the following conditions are | 3 # modification, are permitted provided that the following conditions are |
| 4 # met: | 4 # met: |
| 5 # | 5 # |
| 6 # * Redistributions of source code must retain the above copyright | 6 # * Redistributions of source code must retain the above copyright |
| 7 # notice, this list of conditions and the following disclaimer. | 7 # notice, this list of conditions and the following disclaimer. |
| 8 # * Redistributions in binary form must reproduce the above | 8 # * Redistributions in binary form must reproduce the above |
| 9 # copyright notice, this list of conditions and the following | 9 # copyright notice, this list of conditions and the following |
| 10 # disclaimer in the documentation and/or other materials provided | 10 # disclaimer in the documentation and/or other materials provided |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 else: | 57 else: |
| 58 p[0] = self.__cat(p[1], p[2]) | 58 p[0] = self.__cat(p[1], p[2]) |
| 59 | 59 |
| 60 def p_fragment(self, p): | 60 def p_fragment(self, p): |
| 61 '''fragment : literal maybe_modifier | 61 '''fragment : literal maybe_modifier |
| 62 | class maybe_modifier | 62 | class maybe_modifier |
| 63 | group maybe_modifier | 63 | group maybe_modifier |
| 64 | any maybe_modifier | 64 | any maybe_modifier |
| 65 ''' | 65 ''' |
| 66 if p[2] != None: | 66 if p[2] != None: |
| 67 p[0] = (p[2], p[1]) | 67 if isinstance(p[2], tuple) and p[2][0] == 'REPEAT': |
| 68 p[0] = (p[2][0], p[2][1], p[2][2], p[1]) |
| 69 else: |
| 70 p[0] = (p[2], p[1]) |
| 68 else: | 71 else: |
| 69 p[0] = p[1] | 72 p[0] = p[1] |
| 70 | 73 |
| 71 def p_maybe_modifier(self, p): | 74 def p_maybe_modifier(self, p): |
| 72 '''maybe_modifier : ONE_OR_MORE | 75 '''maybe_modifier : ONE_OR_MORE |
| 73 | ZERO_OR_ONE | 76 | ZERO_OR_ONE |
| 74 | ZERO_OR_MORE | 77 | ZERO_OR_MORE |
| 78 | repetition |
| 75 | empty''' | 79 | empty''' |
| 76 p[0] = p[1] | 80 p[0] = p[1] |
| 77 if p[1] != None: | 81 if p[1] in self.token_map: |
| 78 p[0] = self.token_map[p[1]] | 82 p[0] = self.token_map[p[1]] |
| 79 | 83 |
| 84 def p_repetition(self, p): |
| 85 '''repetition : REPEAT_BEGIN NUMBER REPEAT_END |
| 86 | REPEAT_BEGIN NUMBER COMMA NUMBER REPEAT_END''' |
| 87 if len(p) == 4: |
| 88 p[0] = ("REPEAT", p[2], p[2]) |
| 89 else: |
| 90 p[0] = ("REPEAT", p[2], p[4]) |
| 91 |
| 80 def p_literal(self, p): | 92 def p_literal(self, p): |
| 81 '''literal : LITERAL''' | 93 '''literal : LITERAL''' |
| 82 p[0] = ('LITERAL', p[1]) | 94 p[0] = ('LITERAL', p[1]) |
| 83 | 95 |
| 84 def p_any(self, p): | 96 def p_any(self, p): |
| 85 '''any : ANY''' | 97 '''any : ANY''' |
| 86 p[0] = (self.token_map[p[1]],) | 98 p[0] = (self.token_map[p[1]],) |
| 87 | 99 |
| 88 def p_class(self, p): | 100 def p_class(self, p): |
| 89 '''class : CLASS_BEGIN class_content CLASS_END | 101 '''class : CLASS_BEGIN class_content CLASS_END |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 def build(self, **kwargs): | 143 def build(self, **kwargs): |
| 132 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) | 144 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) |
| 133 self.lexer = RegexLexer() | 145 self.lexer = RegexLexer() |
| 134 self.lexer.build(**kwargs) | 146 self.lexer.build(**kwargs) |
| 135 | 147 |
| 136 @staticmethod | 148 @staticmethod |
| 137 def parse(data): | 149 def parse(data): |
| 138 parser = RegexParser() | 150 parser = RegexParser() |
| 139 parser.build() | 151 parser.build() |
| 140 return parser.parser.parse(data, lexer=parser.lexer.lexer) | 152 return parser.parser.parse(data, lexer=parser.lexer.lexer) |
| OLD | NEW |