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

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

Issue 59033005: Experimental parser: build regex parse trees for all rules (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/regex_lexer.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 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
101 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content 101 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content
102 | CLASS_LITERAL maybe_class_content 102 | CLASS_LITERAL maybe_class_content
103 | CHARACTER_CLASS maybe_class_content 103 | CHARACTER_CLASS maybe_class_content
104 ''' 104 '''
105 if len(p) == 5: 105 if len(p) == 5:
106 left = ("RANGE", p[1], p[3]) 106 left = ("RANGE", p[1], p[3])
107 else: 107 else:
108 if len(p[1]) == 1: 108 if len(p[1]) == 1:
109 left = ('LITERAL', p[1]) 109 left = ('LITERAL', p[1])
110 else: 110 else:
111 left = ('CHARACTER_CLASS', p[1:-1]) 111 left = ('CHARACTER_CLASS', p[1][1:-1])
112 p[0] = self.__cat(left, p[len(p)-1]) 112 p[0] = self.__cat(left, p[len(p)-1])
113 113
114 def p_maybe_class_content(self, p): 114 def p_maybe_class_content(self, p):
115 '''maybe_class_content : class_content 115 '''maybe_class_content : class_content
116 | empty''' 116 | empty'''
117 p[0] = p[1] 117 p[0] = p[1]
118 118
119 def p_empty(self, p): 119 def p_empty(self, p):
120 'empty :' 120 'empty :'
121 121
122 def p_error(self, p): 122 def p_error(self, p):
123 raise Exception("Syntax error in input '%s'" % p) 123 raise Exception("Syntax error in input '%s'" % p)
124 124
125 @staticmethod 125 @staticmethod
126 def __cat(left, right): 126 def __cat(left, right):
127 if right == None: 127 if right == None:
128 return left 128 return left
129 return ('CAT', left, right) 129 return ('CAT', left, right)
130 130
131 def build(self, **kwargs): 131 def build(self, **kwargs):
132 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs) 132 self.parser = yacc.yacc(module=self, debug=0, write_tables=0, **kwargs)
133 self.lexer = RegexLexer() 133 self.lexer = RegexLexer()
134 self.lexer.build(**kwargs) 134 self.lexer.build(**kwargs)
135 135
136 @staticmethod 136 @staticmethod
137 def parse(data): 137 def parse(data):
138 parser = RegexParser() 138 parser = RegexParser()
139 parser.build() 139 parser.build()
140 return parser.parser.parse(data, lexer=parser.lexer.lexer) 140 return parser.parser.parse(data, lexer=parser.lexer.lexer)
OLDNEW
« no previous file with comments | « tools/lexer_generator/regex_lexer.py ('k') | tools/lexer_generator/rule_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698