Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(83)

Unified Diff: mojo/public/tools/bindings/pylib/mojom/parse/parser.py

Issue 382553004: Mojo: Mojom: Add AST types for imports and import lists. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/ast.py ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/tools/bindings/pylib/mojom/parse/parser.py
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
index 97c5dcaa5ce953d6bf1aa7dbb0fbfbc70c8ecff2..c3f8ca4a6f5d4f0a3488d972c24505b3475442c5 100644
--- a/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/parser.py
@@ -87,26 +87,34 @@ class Parser(object):
# See http://www.dabeaz.com/ply/ply.html#ply_nn25 for more details.
# TODO(vtl): Get rid of this ('MODULE', ...) stuff and replace it with an
- # ast.Mojom node. This will require putting the imports into a list (say
- # ast.ImportList).
+ # ast.Mojom node. (The ('IMPORT', ...) stuff is a hack until I do this and
+ # update translate.py.)
# TODO(vtl): Get rid of the braces in the module "statement". (Consider
# renaming "module" -> "package".)
def p_root(self, p):
- """root : import root
- | module LBRACE definition_list RBRACE
- | definition_list"""
- if len(p) == 3:
- p[0] = p[2]
- p[0].insert(0, p[1])
- elif len(p) == 5:
- p[0] = [('MODULE', p[1].name, p[1].attribute_list, p[3])]
+ """root : import_list module LBRACE definition_list RBRACE
+ | import_list definition_list"""
+ p[0] = [('IMPORT', import_statement.import_filename) \
+ for import_statement in p[1]]
+ if len(p) == 6:
+ p[0].append(('MODULE', p[2].name, p[2].attribute_list, p[4]))
else:
- p[0] = [('MODULE', None, None, p[1])]
+ p[0].append(('MODULE', None, None, p[2]))
+
+ def p_import_list_1(self, p):
+ """import_list : """
+ p[0] = ast.ImportList()
+
+ def p_import_list_2(self, p):
+ """import_list : import_list import"""
+ p[0] = p[1]
+ p[0].Append(p[2])
def p_import(self, p):
"""import : IMPORT STRING_LITERAL"""
# 'eval' the literal to strip the quotes.
- p[0] = ('IMPORT', eval(p[2]))
+ # TODO(vtl): This eval is dubious. We should unquote/unescape ourselves.
+ p[0] = ast.Import(eval(p[2]))
def p_module(self, p):
"""module : attribute_section MODULE identifier_wrapped """
« no previous file with comments | « mojo/public/tools/bindings/pylib/mojom/parse/ast.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698