| 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 |
| 11 # Disable lint check for finding modules: | |
| 12 # pylint: disable=F0401 | |
| 13 | |
| 14 def _GetDirAbove(dirname): | 11 def _GetDirAbove(dirname): |
| 15 """Returns the directory "above" this file containing |dirname| (which must | 12 """Returns the directory "above" this file containing |dirname| (which must |
| 16 also be "above" this file).""" | 13 also be "above" this file).""" |
| 17 path = os.path.abspath(__file__) | 14 path = os.path.abspath(__file__) |
| 18 while True: | 15 while True: |
| 19 path, tail = os.path.split(path) | 16 path, tail = os.path.split(path) |
| 20 assert tail | 17 assert tail |
| 21 if tail == dirname: | 18 if tail == dirname: |
| 22 return path | 19 return path |
| 23 | 20 |
| 24 try: | 21 try: |
| 25 imp.find_module("ply") | 22 imp.find_module("ply") |
| 26 except ImportError: | 23 except ImportError: |
| 27 sys.path.append(os.path.join(_GetDirAbove("mojo"), "third_party")) | 24 sys.path.append(os.path.join(_GetDirAbove("mojo"), "third_party")) |
| 28 from ply import lex | 25 from ply import lex |
| 29 from ply import yacc | 26 from ply import yacc |
| 30 | 27 |
| 31 from ..error import Error | 28 from ..error import Error |
| 32 import ast | 29 from . import ast |
| 33 from lexer import Lexer | 30 from .lexer import Lexer |
| 34 | 31 |
| 35 | 32 |
| 36 _MAX_ORDINAL_VALUE = 0xffffffff | 33 _MAX_ORDINAL_VALUE = 0xffffffff |
| 37 _MAX_ARRAY_SIZE = 0xffffffff | 34 _MAX_ARRAY_SIZE = 0xffffffff |
| 38 | 35 |
| 39 | 36 |
| 40 # Disable lint check for exceptions deriving from Exception: | |
| 41 # pylint: disable=W0710 | |
| 42 class ParseError(Error): | 37 class ParseError(Error): |
| 43 """Class for errors from the parser.""" | 38 """Class for errors from the parser.""" |
| 44 | 39 |
| 45 def __init__(self, filename, message, lineno=None, snippet=None): | 40 def __init__(self, filename, message, lineno=None, snippet=None): |
| 46 Error.__init__(self, filename, message, lineno=lineno, | 41 Error.__init__(self, filename, message, lineno=lineno, |
| 47 addenda=([snippet] if snippet else None)) | 42 addenda=([snippet] if snippet else None)) |
| 48 | 43 |
| 49 | 44 |
| 50 # We have methods which look like they could be functions: | 45 # We have methods which look like they could be functions: |
| 51 # pylint: disable=R0201 | 46 # pylint: disable=R0201 |
| (...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 371 | 366 |
| 372 def Parse(source, filename): | 367 def Parse(source, filename): |
| 373 lexer = Lexer(filename) | 368 lexer = Lexer(filename) |
| 374 parser = Parser(lexer, source, filename) | 369 parser = Parser(lexer, source, filename) |
| 375 | 370 |
| 376 lex.lex(object=lexer) | 371 lex.lex(object=lexer) |
| 377 yacc.yacc(module=parser, debug=0, write_tables=0) | 372 yacc.yacc(module=parser, debug=0, write_tables=0) |
| 378 | 373 |
| 379 tree = yacc.parse(source) | 374 tree = yacc.parse(source) |
| 380 return tree | 375 return tree |
| OLD | NEW |