| 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 'IDENTIFIER', | 33 'IDENTIFIER', |
| 34 'STRING_REGEX', | 34 'STRING', |
| 35 'REGEX', |
| 35 'CHARACTER_CLASS_REGEX', | 36 'CHARACTER_CLASS_REGEX', |
| 36 'TRANSITION', | 37 'TRANSITION', |
| 37 'TRANSITION_WITH_CODE', | 38 'TRANSITION_WITH_CODE', |
| 38 | 39 |
| 39 'PLUS', | 40 'PLUS', |
| 40 'QUESTION_MARK', | 41 'QUESTION_MARK', |
| 41 'EQUALS', | 42 'EQUALS', |
| 42 'OR', | 43 'OR', |
| 43 'STAR', | 44 'STAR', |
| 44 'LEFT_PARENTHESIS', | 45 'LEFT_PARENTHESIS', |
| (...skipping 13 matching lines...) Expand all Loading... |
| 58 ) | 59 ) |
| 59 | 60 |
| 60 t_ignore = " \t\n\r" | 61 t_ignore = " \t\n\r" |
| 61 t_code_ignore = "" | 62 t_code_ignore = "" |
| 62 | 63 |
| 63 def t_COMMENT(self, t): | 64 def t_COMMENT(self, t): |
| 64 r'\#.*[\n\r]+' | 65 r'\#.*[\n\r]+' |
| 65 pass | 66 pass |
| 66 | 67 |
| 67 t_IDENTIFIER = r'[a-zA-Z0-9_]+' | 68 t_IDENTIFIER = r'[a-zA-Z0-9_]+' |
| 68 t_STRING_REGEX = r'"((\\("|\w|\\))|[^\\"])+"' | 69 t_STRING = r'"((\\("|\w|\\))|[^\\"])+"' |
| 70 t_REGEX = r'/[^\/]+/' |
| 69 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' | 71 t_CHARACTER_CLASS_REGEX = r'\[([^\]]|\\\])+\]' |
| 70 t_TRANSITION = r':=>' | 72 t_TRANSITION = r':=>' |
| 71 t_TRANSITION_WITH_CODE = r'=>' | 73 t_TRANSITION_WITH_CODE = r'=>' |
| 72 | 74 |
| 73 t_PLUS = r'\+' | 75 t_PLUS = r'\+' |
| 74 t_QUESTION_MARK = r'\?' | 76 t_QUESTION_MARK = r'\?' |
| 75 t_STAR = r'\*' | 77 t_STAR = r'\*' |
| 76 t_OR = r'\|' | 78 t_OR = r'\|' |
| 77 t_EQUALS = r'=' | 79 t_EQUALS = r'=' |
| 78 t_LEFT_PARENTHESIS = r'\(' | 80 t_LEFT_PARENTHESIS = r'\(' |
| (...skipping 23 matching lines...) Expand all Loading... |
| 102 t.type = 'CODE_FRAGMENT' | 104 t.type = 'CODE_FRAGMENT' |
| 103 else: | 105 else: |
| 104 self.lexer.pop_state() | 106 self.lexer.pop_state() |
| 105 return t | 107 return t |
| 106 | 108 |
| 107 def t_ANY_error(self, t): | 109 def t_ANY_error(self, t): |
| 108 raise Exception("Illegal character '%s'" % t.value[0]) | 110 raise Exception("Illegal character '%s'" % t.value[0]) |
| 109 | 111 |
| 110 def build(self, **kwargs): | 112 def build(self, **kwargs): |
| 111 self.lexer = lex.lex(module=self, **kwargs) | 113 self.lexer = lex.lex(module=self, **kwargs) |
| OLD | NEW |