| 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 13 matching lines...) Expand all Loading... |
| 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 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 'IDENTIFIER', | 35 'IDENTIFIER', |
| 35 'STRING', | 36 'STRING', |
| 36 'REGEX', | 37 'REGEX', |
| 37 'CHARACTER_CLASS_REGEX', | 38 'CHARACTER_CLASS_REGEX', |
| 38 | 39 |
| 39 'PLUS', | 40 'PLUS', |
| 40 'QUESTION_MARK', | 41 'QUESTION_MARK', |
| 41 'EQUALS', | 42 'EQUALS', |
| 42 'OR', | 43 'OR', |
| 43 'STAR', | 44 'STAR', |
| (...skipping 19 matching lines...) Expand all Loading... |
| 63 t_code_ignore = "" | 64 t_code_ignore = "" |
| 64 | 65 |
| 65 def t_COMMENT(self, t): | 66 def t_COMMENT(self, t): |
| 66 r'\#.*[\n\r]+' | 67 r'\#.*[\n\r]+' |
| 67 pass | 68 pass |
| 68 | 69 |
| 69 def t_IDENTIFIER(self, t): | 70 def t_IDENTIFIER(self, t): |
| 70 r'[a-zA-Z][a-zA-Z0-9_]*' | 71 r'[a-zA-Z][a-zA-Z0-9_]*' |
| 71 if t.value == 'default': | 72 if t.value == 'default': |
| 72 t.type = 'DEFAULT' | 73 t.type = 'DEFAULT' |
| 74 if t.value == 'default_action': |
| 75 t.type = 'DEFAULT_ACTION' |
| 73 return t | 76 return t |
| 74 | 77 |
| 75 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' | 78 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' |
| 76 t_REGEX = r'/[^\/]+/' | 79 t_REGEX = r'/[^\/]+/' |
| 77 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' | 80 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' |
| 78 | 81 |
| 79 t_PLUS = r'\+' | 82 t_PLUS = r'\+' |
| 80 t_QUESTION_MARK = r'\?' | 83 t_QUESTION_MARK = r'\?' |
| 81 t_STAR = r'\*' | 84 t_STAR = r'\*' |
| 82 t_OR = r'\|' | 85 t_OR = r'\|' |
| (...skipping 27 matching lines...) Expand all Loading... |
| 110 t.type = 'CODE_FRAGMENT' | 113 t.type = 'CODE_FRAGMENT' |
| 111 else: | 114 else: |
| 112 self.lexer.pop_state() | 115 self.lexer.pop_state() |
| 113 return t | 116 return t |
| 114 | 117 |
| 115 def t_ANY_error(self, t): | 118 def t_ANY_error(self, t): |
| 116 raise Exception("Illegal character '%s'" % t.value[0]) | 119 raise Exception("Illegal character '%s'" % t.value[0]) |
| 117 | 120 |
| 118 def build(self, **kwargs): | 121 def build(self, **kwargs): |
| 119 self.lexer = lex.lex(module=self, **kwargs) | 122 self.lexer = lex.lex(module=self, **kwargs) |
| OLD | NEW |