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 19 matching lines...) Expand all Loading... |
30 | 30 |
31 from ..error import Error | 31 from ..error import Error |
32 import ast | 32 import ast |
33 from lexer import Lexer | 33 from lexer import Lexer |
34 | 34 |
35 | 35 |
36 _MAX_ORDINAL_VALUE = 0xffffffff | 36 _MAX_ORDINAL_VALUE = 0xffffffff |
37 _MAX_ARRAY_SIZE = 0xffffffff | 37 _MAX_ARRAY_SIZE = 0xffffffff |
38 | 38 |
39 | 39 |
40 def _ListFromConcat(*items): | |
41 """Generate list by concatenating inputs (note: only concatenates lists, not | |
42 tuples or other iterables).""" | |
43 itemsout = [] | |
44 for item in items: | |
45 if item is None: | |
46 continue | |
47 if type(item) is not type([]): | |
48 itemsout.append(item) | |
49 else: | |
50 itemsout.extend(item) | |
51 return itemsout | |
52 | |
53 | |
54 # Disable lint check for exceptions deriving from Exception: | 40 # Disable lint check for exceptions deriving from Exception: |
55 # pylint: disable=W0710 | 41 # pylint: disable=W0710 |
56 class ParseError(Error): | 42 class ParseError(Error): |
57 """Class for errors from the parser.""" | 43 """Class for errors from the parser.""" |
58 | 44 |
59 def __init__(self, filename, message, lineno=None, snippet=None): | 45 def __init__(self, filename, message, lineno=None, snippet=None): |
60 Error.__init__(self, filename, message, lineno=lineno, | 46 Error.__init__(self, filename, message, lineno=lineno, |
61 addenda=([snippet] if snippet else None)) | 47 addenda=([snippet] if snippet else None)) |
62 | 48 |
63 | 49 |
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 | 371 |
386 def Parse(source, filename): | 372 def Parse(source, filename): |
387 lexer = Lexer(filename) | 373 lexer = Lexer(filename) |
388 parser = Parser(lexer, source, filename) | 374 parser = Parser(lexer, source, filename) |
389 | 375 |
390 lex.lex(object=lexer) | 376 lex.lex(object=lexer) |
391 yacc.yacc(module=parser, debug=0, write_tables=0) | 377 yacc.yacc(module=parser, debug=0, write_tables=0) |
392 | 378 |
393 tree = yacc.parse(source) | 379 tree = yacc.parse(source) |
394 return tree | 380 return tree |
OLD | NEW |