| 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 15 matching lines...) Expand all Loading... |
| 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 import ply.lex as lex | 28 import ply.lex as lex |
| 29 | 29 |
| 30 class RuleLexer: | 30 class RuleLexer: |
| 31 | 31 |
| 32 tokens = ( | 32 tokens = ( |
| 33 'DEFAULT', | 33 'DEFAULT', |
| 34 'DEFAULT_ACTION', | 34 'DEFAULT_ACTION', |
| 35 'CATCH_ALL', | 35 'CATCH_ALL', |
| 36 'PUSH_TOKEN', |
| 36 | 37 |
| 37 'IDENTIFIER', | 38 'IDENTIFIER', |
| 38 'STRING', | 39 'STRING', |
| 39 'REGEX', | 40 'REGEX', |
| 40 'CHARACTER_CLASS_REGEX', | 41 'CHARACTER_CLASS_REGEX', |
| 41 | 42 |
| 42 'PLUS', | 43 'PLUS', |
| 43 'QUESTION_MARK', | 44 'QUESTION_MARK', |
| 44 'EQUALS', | 45 'EQUALS', |
| 45 'OR', | 46 'OR', |
| (...skipping 17 matching lines...) Expand all Loading... |
| 63 ) | 64 ) |
| 64 | 65 |
| 65 t_ignore = " \t\n\r" | 66 t_ignore = " \t\n\r" |
| 66 t_code_ignore = "" | 67 t_code_ignore = "" |
| 67 | 68 |
| 68 def t_COMMENT(self, t): | 69 def t_COMMENT(self, t): |
| 69 r'\#.*[\n\r]+' | 70 r'\#.*[\n\r]+' |
| 70 pass | 71 pass |
| 71 | 72 |
| 72 __special_identifiers = set(map(lambda s: s.lower(), | 73 __special_identifiers = set(map(lambda s: s.lower(), |
| 73 ['DEFAULT', 'DEFAULT_ACTION', 'CATCH_ALL',])) | 74 ['DEFAULT', 'DEFAULT_ACTION', 'CATCH_ALL', 'PUSH_TOKEN'])) |
| 74 | 75 |
| 75 def t_IDENTIFIER(self, t): | 76 def t_IDENTIFIER(self, t): |
| 76 r'[a-zA-Z][a-zA-Z0-9_]*' | 77 r'[a-zA-Z][a-zA-Z0-9_]*' |
| 77 if t.value in self.__special_identifiers: | 78 if t.value in self.__special_identifiers: |
| 78 t.type = t.value.upper() | 79 t.type = t.value.upper() |
| 79 return t | 80 return t |
| 80 | 81 |
| 81 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' | 82 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' |
| 82 t_REGEX = r'/[^\/]+/' | 83 t_REGEX = r'/[^\/]+/' |
| 83 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' | 84 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 t.type = 'CODE_FRAGMENT' | 117 t.type = 'CODE_FRAGMENT' |
| 117 else: | 118 else: |
| 118 self.lexer.pop_state() | 119 self.lexer.pop_state() |
| 119 return t | 120 return t |
| 120 | 121 |
| 121 def t_ANY_error(self, t): | 122 def t_ANY_error(self, t): |
| 122 raise Exception("Illegal character '%s'" % t.value[0]) | 123 raise Exception("Illegal character '%s'" % t.value[0]) |
| 123 | 124 |
| 124 def build(self, **kwargs): | 125 def build(self, **kwargs): |
| 125 self.lexer = lex.lex(module=self, **kwargs) | 126 self.lexer = lex.lex(module=self, **kwargs) |
| OLD | NEW |