| 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 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 | 79 |
| 80 def p_state_change(self, p): | 80 def p_state_change(self, p): |
| 81 '''state_change : LESS_THAN IDENTIFIER GREATER_THAN | 81 '''state_change : LESS_THAN IDENTIFIER GREATER_THAN |
| 82 | LESS_THAN DEFAULT GREATER_THAN''' | 82 | LESS_THAN DEFAULT GREATER_THAN''' |
| 83 state = self.__state | 83 state = self.__state |
| 84 state.current_state = p[2] | 84 state.current_state = p[2] |
| 85 assert state.current_state | 85 assert state.current_state |
| 86 if not state.current_state in state.rules: | 86 if not state.current_state in state.rules: |
| 87 state.rules[state.current_state] = { | 87 state.rules[state.current_state] = { |
| 88 'default_action': None, | 88 'default_action': None, |
| 89 'catch_all' : None, |
| 89 'regex' : [] | 90 'regex' : [] |
| 90 } | 91 } |
| 91 p[0] = state.current_state | 92 p[0] = state.current_state |
| 92 | 93 |
| 93 def p_transition_rules(self, p): | 94 def p_transition_rules(self, p): |
| 94 '''transition_rules : transition_rule transition_rules | 95 '''transition_rules : transition_rule transition_rules |
| 95 | empty''' | 96 | empty''' |
| 96 | 97 |
| 97 def p_transition_rule(self, p): | 98 def p_transition_rule(self, p): |
| 98 '''transition_rule : composite_regex code action | 99 '''transition_rule : composite_regex code action |
| 99 | composite_regex empty action | 100 | composite_regex empty action |
| 100 | composite_regex code empty | 101 | composite_regex code empty |
| 101 | DEFAULT_ACTION code empty''' | 102 | DEFAULT_ACTION code empty |
| 102 transition = p[3] if p[3] else 'break' | 103 | CATCH_ALL empty action''' |
| 103 if not transition in self.__keyword_transitions: | 104 transition = p[3] |
| 105 if transition and not transition in self.__keyword_transitions: |
| 104 assert not transition == 'default' | 106 assert not transition == 'default' |
| 105 self.__state.transitions.add(transition) | 107 self.__state.transitions.add(transition) |
| 106 RuleParser.__rule_precedence_counter += 1 | 108 RuleParser.__rule_precedence_counter += 1 |
| 107 rules = self.__state.rules[self.__state.current_state] | 109 rules = self.__state.rules[self.__state.current_state] |
| 108 code = p[2] | 110 code = p[2] |
| 109 if p[1] == 'default_action': | 111 if p[1] == 'default_action': |
| 110 assert not rules['default_action'] | 112 assert not rules['default_action'] |
| 111 rules['default_action'] = code | 113 rules['default_action'] = code |
| 114 elif p[1] == 'catch_all': |
| 115 assert not rules['catch_all'] |
| 116 rules['catch_all'] = transition |
| 112 else: | 117 else: |
| 113 rule = (p[1], (RuleParser.__rule_precedence_counter, code, transition)) | 118 rule = (p[1], (RuleParser.__rule_precedence_counter, code, transition)) |
| 114 rules['regex'].append(rule) | 119 rules['regex'].append(rule) |
| 115 | 120 |
| 116 def p_action(self, p): | 121 def p_action(self, p): |
| 117 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE' | 122 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE' |
| 118 p[0] = p[2] | 123 p[0] = p[2] |
| 119 | 124 |
| 120 def p_composite_regex(self, p): | 125 def p_composite_regex(self, p): |
| 121 '''composite_regex : regex_parts OR regex_parts | 126 '''composite_regex : regex_parts OR regex_parts |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 parser.build() | 205 parser.build() |
| 201 RuleParser.__static_instance = parser | 206 RuleParser.__static_instance = parser |
| 202 parser.__state = parser_state | 207 parser.__state = parser_state |
| 203 try: | 208 try: |
| 204 parser.parser.parse(data, lexer=parser.lexer.lexer) | 209 parser.parser.parse(data, lexer=parser.lexer.lexer) |
| 205 except Exception: | 210 except Exception: |
| 206 RuleParser.__static_instance = None | 211 RuleParser.__static_instance = None |
| 207 raise | 212 raise |
| 208 parser.__state = None | 213 parser.__state = None |
| 209 assert parser_state.transitions <= set(parser_state.rules.keys()) | 214 assert parser_state.transitions <= set(parser_state.rules.keys()) |
| OLD | NEW |