OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright 2014 The Chromium Authors. All rights reserved. | 2 # Copyright 2014 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 import imp | 8 import imp |
9 import os.path | 9 import os.path |
10 import sys | 10 import sys |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 def p_root(self, p): | 73 def p_root(self, p): |
74 """root : import root | 74 """root : import root |
75 | module | 75 | module |
76 | definitions""" | 76 | definitions""" |
77 if len(p) > 2: | 77 if len(p) > 2: |
78 p[0] = _ListFromConcat(p[1], p[2]) | 78 p[0] = _ListFromConcat(p[1], p[2]) |
79 else: | 79 else: |
80 # Generator expects a module. If one wasn't specified insert one with an | 80 # Generator expects a module. If one wasn't specified insert one with an |
81 # empty name. | 81 # empty name. |
82 if p[1][0] != 'MODULE': | 82 if p[1][0] != 'MODULE': |
83 p[0] = [('MODULE', '', p[1])] | 83 p[0] = [('MODULE', '', [], p[1])] |
84 else: | 84 else: |
85 p[0] = [p[1]] | 85 p[0] = [p[1]] |
86 | 86 |
87 def p_import(self, p): | 87 def p_import(self, p): |
88 """import : IMPORT STRING_LITERAL""" | 88 """import : IMPORT STRING_LITERAL""" |
89 # 'eval' the literal to strip the quotes. | 89 # 'eval' the literal to strip the quotes. |
90 p[0] = ('IMPORT', eval(p[2])) | 90 p[0] = ('IMPORT', eval(p[2])) |
91 | 91 |
92 def p_module(self, p): | 92 def p_module(self, p): |
93 """module : MODULE identifier LBRACE definitions RBRACE""" | 93 """module : attribute_section MODULE identifier LBRACE definitions RBRACE""" |
94 p[0] = ('MODULE', p[2], p[4]) | 94 p[0] = ('MODULE', p[3], p[1], p[5]) |
95 | 95 |
96 def p_definitions(self, p): | 96 def p_definitions(self, p): |
97 """definitions : definition definitions | 97 """definitions : definition definitions |
98 | """ | 98 | """ |
99 if len(p) > 1: | 99 if len(p) > 1: |
100 p[0] = _ListFromConcat(p[1], p[2]) | 100 p[0] = _ListFromConcat(p[1], p[2]) |
101 | 101 |
102 def p_definition(self, p): | 102 def p_definition(self, p): |
103 """definition : struct | 103 """definition : struct |
104 | interface | 104 | interface |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
374 print Parse(f.read(), filename) | 374 print Parse(f.read(), filename) |
375 except ParseError, e: | 375 except ParseError, e: |
376 print e | 376 print e |
377 return 1 | 377 return 1 |
378 | 378 |
379 return 0 | 379 return 0 |
380 | 380 |
381 | 381 |
382 if __name__ == '__main__': | 382 if __name__ == '__main__': |
383 sys.exit(main(sys.argv)) | 383 sys.exit(main(sys.argv)) |
OLD | NEW |