| OLD | NEW |
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 | 63 |
| 64 class Parser(object): | 64 class Parser(object): |
| 65 | 65 |
| 66 def __init__(self, lexer, source, filename): | 66 def __init__(self, lexer, source, filename): |
| 67 self.tokens = lexer.tokens | 67 self.tokens = lexer.tokens |
| 68 self.source = source | 68 self.source = source |
| 69 self.filename = filename | 69 self.filename = filename |
| 70 | 70 |
| 71 def p_root(self, p): | 71 def p_root(self, p): |
| 72 """root : import root | 72 """root : import root |
| 73 | module""" | 73 | module |
| 74 | definitions""" |
| 74 if len(p) > 2: | 75 if len(p) > 2: |
| 75 p[0] = _ListFromConcat(p[1], p[2]) | 76 p[0] = _ListFromConcat(p[1], p[2]) |
| 76 else: | 77 else: |
| 77 p[0] = [p[1]] | 78 if p[1][0] != 'MODULE': |
| 79 p[0] = [('MODULE', '', p[1])] |
| 80 else: |
| 81 p[0] = [p[1]] |
| 78 | 82 |
| 79 def p_import(self, p): | 83 def p_import(self, p): |
| 80 """import : IMPORT STRING_LITERAL""" | 84 """import : IMPORT STRING_LITERAL""" |
| 81 # 'eval' the literal to strip the quotes. | 85 # 'eval' the literal to strip the quotes. |
| 82 p[0] = ('IMPORT', eval(p[2])) | 86 p[0] = ('IMPORT', eval(p[2])) |
| 83 | 87 |
| 84 def p_module(self, p): | 88 def p_module(self, p): |
| 85 """module : MODULE NAME LBRACE definitions RBRACE""" | 89 """module : MODULE NAME LBRACE definitions RBRACE""" |
| 86 p[0] = ('MODULE', p[2], p[4]) | 90 p[0] = ('MODULE', p[2], p[4]) |
| 87 | 91 |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 358 print Parse(f.read(), filename) | 362 print Parse(f.read(), filename) |
| 359 except ParseError, e: | 363 except ParseError, e: |
| 360 print e | 364 print e |
| 361 return 1 | 365 return 1 |
| 362 | 366 |
| 363 return 0 | 367 return 0 |
| 364 | 368 |
| 365 | 369 |
| 366 if __name__ == '__main__': | 370 if __name__ == '__main__': |
| 367 sys.exit(main(sys.argv)) | 371 sys.exit(main(sys.argv)) |
| OLD | NEW |