| 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 220 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 p[0] = ("REPEAT", p[2], p[2]) | 231 p[0] = ("REPEAT", p[2], p[2]) |
| 232 elif len(p) == 6: | 232 elif len(p) == 6: |
| 233 p[0] = ("REPEAT", p[2], p[4]) | 233 p[0] = ("REPEAT", p[2], p[4]) |
| 234 elif p[1]: | 234 elif p[1]: |
| 235 p[0] = (self.token_map[p[1]],) | 235 p[0] = (self.token_map[p[1]],) |
| 236 else: | 236 else: |
| 237 p[0] = None | 237 p[0] = None |
| 238 | 238 |
| 239 def p_literal(self, p): | 239 def p_literal(self, p): |
| 240 '''literal : LITERAL''' | 240 '''literal : LITERAL''' |
| 241 p[0] = Term('LITERAL', p[1]) | 241 p[0] = Term('LITERAL', ord(p[1])) |
| 242 | 242 |
| 243 def p_any(self, p): | 243 def p_any(self, p): |
| 244 '''any : ANY''' | 244 '''any : ANY''' |
| 245 p[0] = Term(self.token_map[p[1]]) | 245 p[0] = Term(self.token_map[p[1]]) |
| 246 | 246 |
| 247 def p_class(self, p): | 247 def p_class(self, p): |
| 248 '''class : CLASS_BEGIN class_content CLASS_END | 248 '''class : CLASS_BEGIN class_content CLASS_END |
| 249 | CLASS_BEGIN NOT class_content CLASS_END''' | 249 | CLASS_BEGIN NOT class_content CLASS_END''' |
| 250 if len(p) == 4: | 250 if len(p) == 4: |
| 251 p[0] = Term("CLASS", p[2]) | 251 p[0] = Term("CLASS", p[2]) |
| 252 else: | 252 else: |
| 253 p[0] = Term("NOT_CLASS", p[3]) | 253 p[0] = Term("NOT_CLASS", p[3]) |
| 254 | 254 |
| 255 def p_group(self, p): | 255 def p_group(self, p): |
| 256 '''group : GROUP_BEGIN start GROUP_END''' | 256 '''group : GROUP_BEGIN start GROUP_END''' |
| 257 p[0] = p[2] | 257 p[0] = p[2] |
| 258 | 258 |
| 259 def p_class_content(self, p): | 259 def p_class_content(self, p): |
| 260 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content | 260 '''class_content : CLASS_LITERAL RANGE CLASS_LITERAL maybe_class_content |
| 261 | CLASS_LITERAL maybe_class_content | 261 | CLASS_LITERAL maybe_class_content |
| 262 | CHARACTER_CLASS maybe_class_content | 262 | CHARACTER_CLASS maybe_class_content |
| 263 ''' | 263 ''' |
| 264 if len(p) == 5: | 264 if len(p) == 5: |
| 265 left = Term("RANGE", p[1], p[3]) | 265 left = Term("RANGE", ord(p[1]), ord(p[3])) |
| 266 else: | 266 else: |
| 267 if len(p[1]) == 1: | 267 if len(p[1]) == 1: |
| 268 left = Term('LITERAL', p[1]) | 268 left = Term('LITERAL', ord(p[1])) |
| 269 else: | 269 else: |
| 270 left = Term('CHARACTER_CLASS', p[1][1:-1]) | 270 left = Term('CHARACTER_CLASS', p[1][1:-1]) |
| 271 p[0] = self.__cat(left, p[len(p)-1]) | 271 p[0] = self.__cat(left, p[len(p)-1]) |
| 272 | 272 |
| 273 def p_maybe_class_content(self, p): | 273 def p_maybe_class_content(self, p): |
| 274 '''maybe_class_content : class_content | 274 '''maybe_class_content : class_content |
| 275 | empty''' | 275 | empty''' |
| 276 p[0] = p[1] | 276 p[0] = p[1] |
| 277 | 277 |
| 278 def p_empty(self, p): | 278 def p_empty(self, p): |
| 279 'empty :' | 279 'empty :' |
| 280 | 280 |
| 281 def p_error(self, p): | 281 def p_error(self, p): |
| 282 raise Exception("Syntax error in input '%s'" % str(p)) | 282 raise Exception("Syntax error in input '%s'" % str(p)) |
| 283 | 283 |
| 284 @staticmethod | 284 @staticmethod |
| 285 def __cat(left, right): | 285 def __cat(left, right): |
| 286 assert left | 286 assert left |
| 287 return NfaBuilder.cat_terms([left] if not right else [left, right]) | 287 return NfaBuilder.cat_terms([left] if not right else [left, right]) |
| 288 | 288 |
| 289 @staticmethod | 289 @staticmethod |
| 290 def parse(string): | 290 def parse(string): |
| 291 new_lexer = lambda: RegexLexer() | 291 new_lexer = lambda: RegexLexer() |
| 292 new_parser = lambda: RegexParser() | 292 new_parser = lambda: RegexParser() |
| 293 return ParserBuilder.parse(string, "RegexParser", new_lexer, new_parser) | 293 return ParserBuilder.parse(string, "RegexParser", new_lexer, new_parser) |
| OLD | NEW |