| 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 '''code_fragments : CODE_FRAGMENT code_fragments | 172 '''code_fragments : CODE_FRAGMENT code_fragments |
| 173 | empty''' | 173 | empty''' |
| 174 p[0] = p[1] | 174 p[0] = p[1] |
| 175 if len(p) == 3 and p[2]: | 175 if len(p) == 3 and p[2]: |
| 176 p[0] = p[1] + p[2] | 176 p[0] = p[1] + p[2] |
| 177 | 177 |
| 178 def p_empty(self, p): | 178 def p_empty(self, p): |
| 179 'empty :' | 179 'empty :' |
| 180 | 180 |
| 181 def p_error(self, p): | 181 def p_error(self, p): |
| 182 raise Exception("Syntax error in input '%s'" % p) | 182 raise Exception("Syntax error in input '%s'" % str(p)) |
| 183 | 183 |
| 184 def build(self, **kwargs): | 184 def build(self, **kwargs): |
| 185 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) | 185 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) |
| 186 self.lexer = RuleLexer() | 186 self.lexer = RuleLexer() |
| 187 self.lexer.build(**kwargs) | 187 self.lexer.build(**kwargs) |
| 188 | 188 |
| 189 __static_instance = None | 189 __static_instance = None |
| 190 @staticmethod | 190 @staticmethod |
| 191 def parse(data, parser_state): | 191 def parse(data, parser_state): |
| 192 if not RuleParser.__static_instance: | |
| 193 RuleParser.__static_instance = RuleParser() | |
| 194 RuleParser.__static_instance.build() | |
| 195 parser = RuleParser.__static_instance | 192 parser = RuleParser.__static_instance |
| 193 if not parser: |
| 194 parser = RuleParser() |
| 195 parser.build() |
| 196 RuleParser.__static_instance = parser |
| 196 parser.__state = parser_state | 197 parser.__state = parser_state |
| 197 parser.parser.parse(data, lexer=parser.lexer.lexer) | 198 try: |
| 199 parser.parser.parse(data, lexer=parser.lexer.lexer) |
| 200 except Exception as e: |
| 201 RuleParser.__static_instance = None |
| 202 raise e |
| 198 parser.__state = None | 203 parser.__state = None |
| OLD | NEW |