| OLD | NEW |
| 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 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | LPAREN expression RPAREN""" | 300 | LPAREN expression RPAREN""" |
| 301 p[0] = _ListFromConcat(*p[1:]) | 301 p[0] = _ListFromConcat(*p[1:]) |
| 302 | 302 |
| 303 def p_identifier(self, p): | 303 def p_identifier(self, p): |
| 304 """identifier : NAME | 304 """identifier : NAME |
| 305 | NAME DOT identifier""" | 305 | NAME DOT identifier""" |
| 306 p[0] = ''.join(p[1:]) | 306 p[0] = ''.join(p[1:]) |
| 307 | 307 |
| 308 def p_constant(self, p): | 308 def p_constant(self, p): |
| 309 """constant : INT_CONST_DEC | 309 """constant : INT_CONST_DEC |
| 310 | INT_CONST_OCT | |
| 311 | INT_CONST_HEX | 310 | INT_CONST_HEX |
| 312 | FLOAT_CONST | 311 | FLOAT_CONST |
| 313 | CHAR_CONST | 312 | CHAR_CONST |
| 314 | STRING_LITERAL""" | 313 | STRING_LITERAL""" |
| 315 p[0] = _ListFromConcat(*p[1:]) | 314 p[0] = _ListFromConcat(*p[1:]) |
| 316 | 315 |
| 317 def p_error(self, e): | 316 def p_error(self, e): |
| 318 if e is None: | 317 if e is None: |
| 319 # Unexpected EOF. | 318 # Unexpected EOF. |
| 320 # TODO(vtl): Can we figure out what's missing? | 319 # TODO(vtl): Can we figure out what's missing? |
| 321 raise ParseError(self.filename, "Unexpected end of file") | 320 raise ParseError(self.filename, "Unexpected end of file") |
| 322 | 321 |
| 323 raise ParseError(self.filename, "Unexpected %r:" % e.value, lineno=e.lineno, | 322 raise ParseError(self.filename, "Unexpected %r:" % e.value, lineno=e.lineno, |
| 324 snippet=self._GetSnippet(e.lineno)) | 323 snippet=self._GetSnippet(e.lineno)) |
| 325 | 324 |
| 326 def _GetSnippet(self, lineno): | 325 def _GetSnippet(self, lineno): |
| 327 return self.source.split('\n')[lineno - 1] | 326 return self.source.split('\n')[lineno - 1] |
| 328 | 327 |
| 329 | 328 |
| 330 def Parse(source, filename): | 329 def Parse(source, filename): |
| 331 lexer = Lexer(filename) | 330 lexer = Lexer(filename) |
| 332 parser = Parser(lexer, source, filename) | 331 parser = Parser(lexer, source, filename) |
| 333 | 332 |
| 334 lex.lex(object=lexer) | 333 lex.lex(object=lexer) |
| 335 yacc.yacc(module=parser, debug=0, write_tables=0) | 334 yacc.yacc(module=parser, debug=0, write_tables=0) |
| 336 | 335 |
| 337 tree = yacc.parse(source) | 336 tree = yacc.parse(source) |
| 338 return tree | 337 return tree |
| OLD | NEW |