Index: mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
diff --git a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
index 6060c83bf960f04be2092fda471965d8534ceccb..6bd4157d34dbac502e6a213ac78b9e2511495ef6 100755 |
--- a/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
+++ b/mojo/public/tools/bindings/pylib/mojom/parse/translate.py |
@@ -41,6 +41,16 @@ def MapKind(kind): |
return map_to_kind[kind] |
return 'x:' + kind |
+def MapAttributes(attributes): |
+ def _AttributeValueToString(v): |
qsr
2014/04/30 13:03:45
Not sure this is the best solution. If you think i
darin (slow to review)
2014/05/02 07:44:01
Do you think that would help us catch syntactic er
qsr
2014/05/05 12:40:05
Finally, I let the expression, and decided to use
|
+ if isinstance(v, basestring): |
+ return v |
+ return ''.join(v[1]) |
+ if not attributes: |
+ return {} |
+ return dict([(attribute[1], _AttributeValueToString(attribute[2])) |
+ for attribute in attributes if attribute[0] == 'ATTRIBUTE']) |
+ |
def GetAttribute(attributes, name): |
out = None |
if attributes: |
@@ -78,8 +88,7 @@ def MapEnumField(tree): |
def MapStruct(tree): |
struct = {} |
struct['name'] = tree[1] |
- # TODO(darin): Add support for |attributes| |
- #struct['attributes'] = MapAttributes(tree[2]) |
+ struct['attributes'] = MapAttributes(tree[2]) |
struct['fields'] = MapTree(MapField, tree[3], 'FIELD') |
struct['enums'] = MapTree(MapEnum, tree[3], 'ENUM') |
return struct |
@@ -102,9 +111,10 @@ def MapModule(tree, name): |
mojom = {} |
mojom['name'] = name |
mojom['namespace'] = tree[1] |
- mojom['structs'] = MapTree(MapStruct, tree[2], 'STRUCT') |
- mojom['interfaces'] = MapTree(MapInterface, tree[2], 'INTERFACE') |
- mojom['enums'] = MapTree(MapEnum, tree[2], 'ENUM') |
+ mojom['attributes'] = MapAttributes(tree[2]) |
+ mojom['structs'] = MapTree(MapStruct, tree[3], 'STRUCT') |
+ mojom['interfaces'] = MapTree(MapInterface, tree[3], 'INTERFACE') |
+ mojom['enums'] = MapTree(MapEnum, tree[3], 'ENUM') |
return mojom |
def MapImport(tree): |