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

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

Issue 47493004: Experimental parser generator: Saner rule parsing. (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/rule_lexer.py ('k') | no next file » | 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 18 matching lines...) Expand all
29 from rule_lexer import RuleLexer 29 from rule_lexer import RuleLexer
30 30
31 class RuleParser: 31 class RuleParser:
32 32
33 tokens = RuleLexer.tokens 33 tokens = RuleLexer.tokens
34 34
35 aliases = dict() 35 aliases = dict()
36 transitions = dict() 36 transitions = dict()
37 37
38 def p_statement_alias(self, p): 38 def p_statement_alias(self, p):
39 'statement : ALIAS' 39 'statement : ALIAS EQUALS REGEX'
40 name = self.lexer.lexer.lexmatch.group('name')
41 regex = self.lexer.lexer.lexmatch.group('regex') 40 regex = self.lexer.lexer.lexmatch.group('regex')
42 self.aliases[name] = regex 41 self.aliases[p[1]] = regex
43 42
44 def p_statement_condition_transition(self, p): 43 def p_statement_condition_transition(self, p):
45 'statement : CONDITION_TRANSITION' 44 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_TRANSITION'
46 old_condition = self.lexer.lexer.lexmatch.group('old') 45 old_condition = p[2]
47 regex = self.lexer.lexer.lexmatch.group('regex') 46 regex = self.lexer.lexer.lexmatch.group('regex')
48 new_condition = self.lexer.lexer.lexmatch.group('new') 47 new_condition = self.lexer.lexer.lexmatch.group('new')
49 if old_condition not in self.transitions: 48 if old_condition not in self.transitions:
50 self.transitions[old_condition] = [] 49 self.transitions[old_condition] = []
51 self.transitions[old_condition].append((regex, new_condition)) 50 self.transitions[old_condition].append((regex, new_condition))
52 51
53 def p_statement_condition(self, p): 52 def p_statement_condition_body(self, p):
54 'statement : CONDITION' 53 'statement : CONDITION_BEGIN CONDITION CONDITION_END REGEX_AND_BODY'
55 old_condition = self.lexer.lexer.lexmatch.group('old') 54 old_condition = p[2]
56 regex = self.lexer.lexer.lexmatch.group('regex') 55 regex = self.lexer.lexer.lexmatch.group('regex')
57 body = self.lexer.lexer.lexmatch.group('body') 56 body = self.lexer.lexer.lexmatch.group('body')
58 if old_condition not in self.transitions: 57 if old_condition not in self.transitions:
59 self.transitions[old_condition] = [] 58 self.transitions[old_condition] = []
60 self.transitions[old_condition].append((regex, body)) 59 self.transitions[old_condition].append((regex, body))
61 60
62 def p_empty(self, p): 61 def p_empty(self, p):
63 'empty :' 62 'empty :'
64 63
65 def p_error(self, p): 64 def p_error(self, p):
66 raise Exception("Syntax error in input '%s'" % p) 65 raise Exception("Syntax error in input '%s'" % p)
67 66
68 def build(self, **kwargs): 67 def build(self, **kwargs):
69 self.parser = yacc.yacc(module=self, **kwargs) 68 self.parser = yacc.yacc(module=self, **kwargs)
70 self.lexer = RuleLexer() 69 self.lexer = RuleLexer()
71 self.lexer.build(**kwargs) 70 self.lexer.build(**kwargs)
72 71
73 def parse(self, data): 72 def parse(self, data):
74 return self.parser.parse(data, lexer=self.lexer.lexer) 73 return self.parser.parse(data, lexer=self.lexer.lexer)
OLDNEW
« no previous file with comments | « tools/lexer_generator/rule_lexer.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698