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

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

Issue 59953002: Experimental lexer generator: parse {} in regexps. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/parser
Patch Set: rebased 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/nfa.py ('k') | tools/lexer_generator/regex_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 25 matching lines...) Expand all
36 36
37 'CLASS_BEGIN', 37 'CLASS_BEGIN',
38 'CLASS_END', 38 'CLASS_END',
39 39
40 'OR', 40 'OR',
41 'ONE_OR_MORE', 41 'ONE_OR_MORE',
42 'ZERO_OR_MORE', 42 'ZERO_OR_MORE',
43 'ZERO_OR_ONE', 43 'ZERO_OR_ONE',
44 'ANY', 44 'ANY',
45 45
46 'REPEAT_BEGIN',
47 'REPEAT_END',
48
49 'NUMBER',
50 'COMMA',
46 'LITERAL', 51 'LITERAL',
47 52
48 'RANGE', 53 'RANGE',
49 'NOT', 54 'NOT',
50 'CLASS_LITERAL', 55 'CLASS_LITERAL',
51 'CHARACTER_CLASS', 56 'CHARACTER_CLASS',
52 ) 57 )
53 58
54 states = ( 59 states = (
55 ('class','exclusive'), 60 ('class','exclusive'),
56 ) 61 )
57 62
58 def t_ESCAPED_LITERAL(self, t): 63 def t_ESCAPED_LITERAL(self, t):
59 r'\\\(|\\\)|\\\[|\\\]|\\\||\\\+|\\\*|\\\?|\\\.|\\\\' 64 r'\\\(|\\\)|\\\[|\\\]|\\\||\\\+|\\\*|\\\?|\\\.|\\\\'
60 t.type = 'LITERAL' 65 t.type = 'LITERAL'
61 t.value = t.value[1:] 66 t.value = t.value[1:]
62 return t 67 return t
63 68
64 t_GROUP_BEGIN = r'\(' 69 t_GROUP_BEGIN = r'\('
65 t_GROUP_END = r'\)' 70 t_GROUP_END = r'\)'
66 71
72 t_REPEAT_BEGIN = r'\{'
73 t_REPEAT_END = r'\}'
74
67 t_OR = r'\|' 75 t_OR = r'\|'
68 t_ONE_OR_MORE = r'\+' 76 t_ONE_OR_MORE = r'\+'
69 t_ZERO_OR_MORE = r'\*' 77 t_ZERO_OR_MORE = r'\*'
70 t_ZERO_OR_ONE = r'\?' 78 t_ZERO_OR_ONE = r'\?'
71 79
80 t_NUMBER = r'[0-9]+'
81 t_COMMA = r','
82
72 t_ANY = r'\.' 83 t_ANY = r'\.'
73 84
74 t_LITERAL = r'.' 85 t_LITERAL = r'.'
75 86
76 def t_CLASS_BEGIN(self, t): 87 def t_CLASS_BEGIN(self, t):
77 r'\[' 88 r'\['
78 self.lexer.push_state('class') 89 self.lexer.push_state('class')
79 return t 90 return t
80 91
81 def t_class_CLASS_END(self, t): 92 def t_class_CLASS_END(self, t):
(...skipping 13 matching lines...) Expand all
95 106
96 t_class_CLASS_LITERAL = r'[\w $_+]' # fix this 107 t_class_CLASS_LITERAL = r'[\w $_+]' # fix this
97 108
98 t_ANY_ignore = '\n' 109 t_ANY_ignore = '\n'
99 110
100 def t_ANY_error(self, t): 111 def t_ANY_error(self, t):
101 raise Exception("Illegal character '%s'" % t.value[0]) 112 raise Exception("Illegal character '%s'" % t.value[0])
102 113
103 def build(self, **kwargs): 114 def build(self, **kwargs):
104 self.lexer = lex.lex(module=self, **kwargs) 115 self.lexer = lex.lex(module=self, **kwargs)
OLDNEW
« no previous file with comments | « tools/lexer_generator/nfa.py ('k') | tools/lexer_generator/regex_parser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698