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

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

Issue 226983002: Mojo: Mojom: Test the parser when there's no module declared. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 8 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 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generates a syntax tree from a Mojo IDL file.""" 6 """Generates a syntax tree from a Mojo IDL file."""
7 7
8 8
9 import sys 9 import sys
10 import os.path 10 import os.path
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 eof=False): 49 eof=False):
50 self.filename = filename 50 self.filename = filename
51 self.lineno = lineno 51 self.lineno = lineno
52 self.snippet = snippet 52 self.snippet = snippet
53 self.bad_char = bad_char 53 self.bad_char = bad_char
54 self.eof = eof 54 self.eof = eof
55 55
56 def __str__(self): 56 def __str__(self):
57 return "%s: Error: Unexpected end of file" % self.filename if self.eof \ 57 return "%s: Error: Unexpected end of file" % self.filename if self.eof \
58 else "%s:%d: Error: Unexpected %r:\n%s" % ( 58 else "%s:%d: Error: Unexpected %r:\n%s" % (
59 self.filename, self.lineno + 1, self.bad_char, self.snippet) 59 self.filename, self.lineno, self.bad_char, self.snippet)
60 60
61 def __repr__(self): 61 def __repr__(self):
62 return str(self) 62 return str(self)
63 63
64 64
65 class Parser(object): 65 class Parser(object):
66 66
67 def __init__(self, lexer, source, filename): 67 def __init__(self, lexer, source, filename):
68 self.tokens = lexer.tokens 68 self.tokens = lexer.tokens
69 self.source = source 69 self.source = source
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 | CHAR_CONST 327 | CHAR_CONST
328 | STRING_LITERAL""" 328 | STRING_LITERAL"""
329 p[0] = _ListFromConcat(*p[1:]) 329 p[0] = _ListFromConcat(*p[1:])
330 330
331 def p_error(self, e): 331 def p_error(self, e):
332 if e is None: 332 if e is None:
333 # Unexpected EOF. 333 # Unexpected EOF.
334 # TODO(vtl): Can we figure out what's missing? 334 # TODO(vtl): Can we figure out what's missing?
335 raise ParseError(self.filename, eof=True) 335 raise ParseError(self.filename, eof=True)
336 336
337 lineno = e.lineno + 1 337 snippet = self.source.split('\n')[e.lineno - 1]
338 snippet = self.source.split('\n')[lineno] 338 raise ParseError(self.filename, lineno=e.lineno, snippet=snippet,
339 raise ParseError(self.filename, lineno=lineno, snippet=snippet,
340 bad_char=e.value) 339 bad_char=e.value)
341 340
342 341
343 def Parse(source, filename): 342 def Parse(source, filename):
344 lexer = Lexer(filename) 343 lexer = Lexer(filename)
345 parser = Parser(lexer, source, filename) 344 parser = Parser(lexer, source, filename)
346 345
347 lex.lex(object=lexer) 346 lex.lex(object=lexer)
348 yacc.yacc(module=parser, debug=0, write_tables=0) 347 yacc.yacc(module=parser, debug=0, write_tables=0)
349 348
(...skipping 13 matching lines...) Expand all
363 print Parse(f.read(), filename) 362 print Parse(f.read(), filename)
364 except ParseError, e: 363 except ParseError, e:
365 print e 364 print e
366 return 1 365 return 1
367 366
368 return 0 367 return 0
369 368
370 369
371 if __name__ == '__main__': 370 if __name__ == '__main__':
372 sys.exit(main(sys.argv)) 371 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « mojo/public/tools/bindings/pylib/parse/mojo_lexer.py ('k') | mojo/public/tools/bindings/pylib/parse/mojo_parser_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698