| 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 29 matching lines...) Expand all Loading... |
| 40 self.character_classes = {} | 40 self.character_classes = {} |
| 41 self.current_state = None | 41 self.current_state = None |
| 42 self.rules = {} | 42 self.rules = {} |
| 43 | 43 |
| 44 def parse(self, string): | 44 def parse(self, string): |
| 45 return RuleParser.parse(string, self) | 45 return RuleParser.parse(string, self) |
| 46 | 46 |
| 47 class RuleParser: | 47 class RuleParser: |
| 48 | 48 |
| 49 tokens = RuleLexer.tokens | 49 tokens = RuleLexer.tokens |
| 50 __rule_precedence_counter = 0 |
| 50 | 51 |
| 51 def __init__(self): | 52 def __init__(self): |
| 52 self.__state = None | 53 self.__state = None |
| 53 | 54 |
| 54 def p_statements(self, p): | 55 def p_statements(self, p): |
| 55 'statements : aliases rules' | 56 'statements : aliases rules' |
| 56 | 57 |
| 57 def p_aliases(self, p): | 58 def p_aliases(self, p): |
| 58 '''aliases : alias_rule aliases | 59 '''aliases : alias_rule aliases |
| 59 | empty''' | 60 | empty''' |
| (...skipping 28 matching lines...) Expand all Loading... |
| 88 | 89 |
| 89 def p_transition_rules(self, p): | 90 def p_transition_rules(self, p): |
| 90 '''transition_rules : transition_rule transition_rules | 91 '''transition_rules : transition_rule transition_rules |
| 91 | empty''' | 92 | empty''' |
| 92 | 93 |
| 93 def p_transition_rule(self, p): | 94 def p_transition_rule(self, p): |
| 94 '''transition_rule : composite_regex_or_default code action | 95 '''transition_rule : composite_regex_or_default code action |
| 95 | composite_regex_or_default empty action | 96 | composite_regex_or_default empty action |
| 96 | composite_regex_or_default code empty''' | 97 | composite_regex_or_default code empty''' |
| 97 rules = self.__state.rules[self.__state.current_state] | 98 rules = self.__state.rules[self.__state.current_state] |
| 98 rule = (p[1], p[2], p[3]) | 99 rule = (p[1], RuleParser.__rule_precedence_counter, p[2], p[3]) |
| 100 RuleParser.__rule_precedence_counter += 1 |
| 99 if p[1] == 'default': | 101 if p[1] == 'default': |
| 100 assert not rules['default'] | 102 assert not rules['default'] |
| 101 rules['default'] = rule | 103 rules['default'] = rule |
| 102 else: | 104 else: |
| 103 rules['regex'].append(rule) | 105 rules['regex'].append(rule) |
| 104 | 106 |
| 105 def p_action(self, p): | 107 def p_action(self, p): |
| 106 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE' | 108 'action : ACTION_OPEN IDENTIFIER ACTION_CLOSE' |
| 107 p[0] = p[2] | 109 p[0] = p[2] |
| 108 | 110 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 __static_instance = None | 189 __static_instance = None |
| 188 @staticmethod | 190 @staticmethod |
| 189 def parse(data, parser_state): | 191 def parse(data, parser_state): |
| 190 if not RuleParser.__static_instance: | 192 if not RuleParser.__static_instance: |
| 191 RuleParser.__static_instance = RuleParser() | 193 RuleParser.__static_instance = RuleParser() |
| 192 RuleParser.__static_instance.build() | 194 RuleParser.__static_instance.build() |
| 193 parser = RuleParser.__static_instance | 195 parser = RuleParser.__static_instance |
| 194 parser.__state = parser_state | 196 parser.__state = parser_state |
| 195 parser.parser.parse(data, lexer=parser.lexer.lexer) | 197 parser.parser.parse(data, lexer=parser.lexer.lexer) |
| 196 parser.__state = None | 198 parser.__state = None |
| OLD | NEW |