Chromium Code Reviews| Index: tools/json_schema_compiler/idl_schema.py |
| diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py |
| index d65746a210af0d24649677719f8291107a474fa6..d2223bc18bb03fb757e032e9c77245ca436ac3bc 100644 |
| --- a/tools/json_schema_compiler/idl_schema.py |
| +++ b/tools/json_schema_compiler/idl_schema.py |
| @@ -37,7 +37,7 @@ def ProcessComment(comment): |
| } |
| ) |
| ''' |
| - # Find all the parameter comments of the form "|name|: comment". |
| + # Find all the parameter comments of the form '|name|: comment'. |
| parameter_comments = re.findall(r'\n *\|([^|]*)\| *: *(.*)', comment) |
| # Get the parent comment (everything before the first parameter comment. |
| parent_comment = re.sub(r'\n *\|.*', '', comment) |
| @@ -104,19 +104,35 @@ class Enum(object): |
| ''' |
| def __init__(self, enum_node): |
| self.node = enum_node |
| + self.description = '' |
| def process(self, callbacks): |
| enum = [] |
| + enum_type = 'integer' |
|
asargent_no_longer_on_chrome
2012/06/07 00:18:08
As I mentioned in another comment, the WebIDL spec
benjhayden
2012/06/08 16:41:52
Done.
|
| for node in self.node.children: |
| if node.cls == 'EnumItem': |
| - name = node.GetName() |
| - enum.append(name) |
| + value = node.GetProperty('VALUE') |
| + if value: |
| + try: |
| + value = int(value) |
| + except ValueError: |
| + try: |
| + value = float(value) |
| + enum_type = 'double' |
| + except ValueError: |
| + enum_type = 'string' |
| + else: |
| + value = node.GetName() |
| + enum_type = 'string' |
| + enum.append(value) |
| + elif node.cls == 'Comment': |
| + self.description = ProcessComment(node.GetName())[0] |
| else: |
| - sys.exit("Did not process %s %s" % (node.cls, node)) |
| - return { "id" : self.node.GetName(), |
| - 'enum': enum, |
| - 'type': 'string' } |
| - |
| + sys.exit('Did not process %s %s' % (node.cls, node)) |
| + return {'id' : self.node.GetName(), |
| + 'description': self.description, |
| + 'type': enum_type, |
| + 'enum': enum} |
| class Member(object): |
| @@ -216,36 +232,42 @@ class Namespace(object): |
| dictionary that the JSON schema compiler expects to see. |
| ''' |
| - def __init__(self, namespace_node, nodoc=False): |
| + def __init__(self, namespace_node, nodoc=False, |
| + permissions=None): |
| self.namespace = namespace_node |
| self.nodoc = nodoc |
| self.events = [] |
| self.functions = [] |
| self.types = [] |
| self.callbacks = {} |
| + self.permissions = permissions or [] |
| def process(self): |
| for node in self.namespace.children: |
| cls = node.cls |
| - if cls == "Dictionary": |
| + if cls == 'Dictionary': |
| self.types.append(Dictionary(node).process(self.callbacks)) |
| - elif cls == "Callback": |
| + elif cls == 'Callback': |
| k, v = Member(node).process(self.callbacks) |
| self.callbacks[k] = v |
| - elif cls == "Interface" and node.GetName() == "Functions": |
| + elif cls == 'Interface' and node.GetName() == 'Functions': |
| self.functions = self.process_interface(node) |
| - elif cls == "Interface" and node.GetName() == "Events": |
| + elif cls == 'Interface' and node.GetName() == 'Events': |
| self.events = self.process_interface(node) |
| - elif cls == "Enum": |
| + elif cls == 'Enum': |
| self.types.append(Enum(node).process(self.callbacks)) |
| + elif cls == 'Member': |
| + name, properties = Member(node).process(self.callbacks) |
| + self.functions.append(properties) |
| else: |
| - sys.exit("Did not process %s %s" % (node.cls, node)) |
| + sys.exit('Did not process %s %s' % (node.cls, node)) |
| - return { 'events': self.events, |
| - 'functions': self.functions, |
| - 'types': self.types, |
| - 'namespace': self.namespace.GetName(), |
| - 'nodoc': self.nodoc } |
| + return {'namespace': self.namespace.GetName(), |
| + 'documentation_permissions_required': self.permissions, |
| + 'nodoc': self.nodoc, |
| + 'types': self.types, |
| + 'events': self.events, |
| + 'functions': self.functions} |
| def process_interface(self, node): |
| members = [] |
| @@ -266,23 +288,24 @@ class IDLSchema(object): |
| def process(self): |
| namespaces = [] |
| + nodoc = False |
| + permissions = None |
| for node in self.idl: |
| - nodoc = False |
| cls = node.cls |
| if cls == 'Namespace': |
| - namespace = Namespace(node, nodoc) |
| + namespace = Namespace(node, nodoc, permissions) |
| namespaces.append(namespace.process()) |
| - elif cls == 'Copyright': |
| - continue |
| - elif cls == 'Comment': |
| + elif cls in ['Copyright', 'Comment']: |
| continue |
| elif cls == 'ExtAttribute': |
| if node.name == 'nodoc': |
| nodoc = bool(node.value) |
| + elif node.name == 'permissions': |
| + permissions = node.value.split(',') |
| else: |
| continue |
| else: |
| - sys.exit("Did not process %s %s" % (node.cls, node)) |
| + sys.exit('Did not process %s %s' % (node.cls, node)) |
| schema_util.PrefixSchemasWithNamespace(namespaces) |
| return namespaces |