Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(827)

Side by Side Diff: tools/lexer_generator/rule_lexer.py

Issue 63773003: Experimental parser: add push_token syntax (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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)
OLDNEW
« no previous file with comments | « tools/lexer_generator/code_generator.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698