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

Side by Side Diff: mojo/public/tools/bindings/pylib/mojom/parse/parser.py

Issue 474063002: Mojo: add support for {double,float}.{INFINITY,NEGATIVE_INFINITY,NAN} (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix test Created 6 years, 4 months 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 """Generates a syntax tree from a Mojo IDL file.""" 5 """Generates a syntax tree from a Mojo IDL file."""
6 6
7 import imp 7 import imp
8 import os.path 8 import os.path
9 import sys 9 import sys
10 10
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 | NAME EQUALS identifier_wrapped""" 312 | NAME EQUALS identifier_wrapped"""
313 p[0] = ast.EnumValue(p[1], p[3] if len(p) == 4 else None, 313 p[0] = ast.EnumValue(p[1], p[3] if len(p) == 4 else None,
314 filename=self.filename, lineno=p.lineno(1)) 314 filename=self.filename, lineno=p.lineno(1))
315 315
316 def p_const(self, p): 316 def p_const(self, p):
317 """const : CONST typename NAME EQUALS constant SEMI""" 317 """const : CONST typename NAME EQUALS constant SEMI"""
318 p[0] = ast.Const(p[3], p[2], p[5]) 318 p[0] = ast.Const(p[3], p[2], p[5])
319 319
320 def p_constant(self, p): 320 def p_constant(self, p):
321 """constant : literal 321 """constant : literal
322 | identifier_wrapped""" 322 | identifier_wrapped"""
viettrungluu 2014/08/21 16:42:18 If you didn't add a lexer token for these, wouldn'
323 p[0] = p[1] 323 p[0] = p[1]
324 324
325 def p_identifier_wrapped(self, p): 325 def p_identifier_wrapped(self, p):
326 """identifier_wrapped : identifier""" 326 """identifier_wrapped : identifier"""
327 p[0] = ('IDENTIFIER', p[1]) 327 p[0] = ('IDENTIFIER', p[1])
328 328
329 # TODO(vtl): Make this produce a "wrapped" identifier (probably as an 329 # TODO(vtl): Make this produce a "wrapped" identifier (probably as an
330 # |ast.Identifier|, to be added) and get rid of identifier_wrapped. 330 # |ast.Identifier|, to be added) and get rid of identifier_wrapped.
331 def p_identifier(self, p): 331 def p_identifier(self, p):
332 """identifier : NAME 332 """identifier : NAME
(...skipping 16 matching lines...) Expand all
349 p[0] = ''.join(p[1:]) 349 p[0] = ''.join(p[1:])
350 350
351 def p_int_const(self, p): 351 def p_int_const(self, p):
352 """int_const : INT_CONST_DEC 352 """int_const : INT_CONST_DEC
353 | INT_CONST_HEX""" 353 | INT_CONST_HEX"""
354 p[0] = p[1] 354 p[0] = p[1]
355 355
356 def p_float(self, p): 356 def p_float(self, p):
357 """float : FLOAT_CONST 357 """float : FLOAT_CONST
358 | PLUS FLOAT_CONST 358 | PLUS FLOAT_CONST
359 | MINUS FLOAT_CONST""" 359 | MINUS FLOAT_CONST
360 | FLOAT_BUILTIN"""
360 p[0] = ''.join(p[1:]) 361 p[0] = ''.join(p[1:])
361 362
362 def p_error(self, e): 363 def p_error(self, e):
363 if e is None: 364 if e is None:
364 # Unexpected EOF. 365 # Unexpected EOF.
365 # TODO(vtl): Can we figure out what's missing? 366 # TODO(vtl): Can we figure out what's missing?
366 raise ParseError(self.filename, "Unexpected end of file") 367 raise ParseError(self.filename, "Unexpected end of file")
367 368
368 raise ParseError(self.filename, "Unexpected %r:" % e.value, lineno=e.lineno, 369 raise ParseError(self.filename, "Unexpected %r:" % e.value, lineno=e.lineno,
369 snippet=self._GetSnippet(e.lineno)) 370 snippet=self._GetSnippet(e.lineno))
370 371
371 def _GetSnippet(self, lineno): 372 def _GetSnippet(self, lineno):
372 return self.source.split('\n')[lineno - 1] 373 return self.source.split('\n')[lineno - 1]
373 374
374 375
375 def Parse(source, filename): 376 def Parse(source, filename):
376 lexer = Lexer(filename) 377 lexer = Lexer(filename)
377 parser = Parser(lexer, source, filename) 378 parser = Parser(lexer, source, filename)
378 379
379 lex.lex(object=lexer) 380 lex.lex(object=lexer)
380 yacc.yacc(module=parser, debug=0, write_tables=0) 381 yacc.yacc(module=parser, debug=0, write_tables=0)
381 382
382 tree = yacc.parse(source) 383 tree = yacc.parse(source)
383 return tree 384 return tree
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698