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..e3f0ff370e5149bcf0d9227bb2fda5bc131f6ebc 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) |
@@ -75,9 +75,9 @@ class Param(object): |
self.node = param_node |
def process(self, callbacks): |
- return Typeref(self.node.GetProperty( 'TYPEREF'), |
+ return Typeref(self.node.GetProperty('TYPEREF'), |
self.node, |
- { 'name': self.node.GetName() }).process(callbacks) |
+ {'name': self.node.GetName()}).process(callbacks) |
class Dictionary(object): |
''' |
@@ -93,31 +93,12 @@ class Dictionary(object): |
if node.cls == 'Member': |
k, v = Member(node).process(callbacks) |
properties[k] = v |
- return { 'id': self.node.GetName(), |
- 'properties': properties, |
- 'type': 'object' } |
- |
-class Enum(object): |
- ''' |
- Given an IDL Enum node, converts into a Python dictionary that the JSON |
- schema compiler expects to see. |
- ''' |
- def __init__(self, enum_node): |
- self.node = enum_node |
- |
- def process(self, callbacks): |
- enum = [] |
- for node in self.node.children: |
- if node.cls == 'EnumItem': |
- name = node.GetName() |
- enum.append(name) |
- else: |
- sys.exit("Did not process %s %s" % (node.cls, node)) |
- return { "id" : self.node.GetName(), |
- 'enum': enum, |
- 'type': 'string' } |
- |
- |
+ result = {'id': self.node.GetName(), |
+ 'properties': properties, |
+ 'type': 'object'} |
+ if self.node.GetProperty('nodoc'): |
+ result['nodoc'] = True |
+ return result |
class Member(object): |
''' |
@@ -131,7 +112,7 @@ class Member(object): |
def process(self, callbacks): |
properties = {} |
name = self.node.GetName() |
- for property_name in ('OPTIONAL', 'nodoc', 'nocompile'): |
+ for property_name in ('OPTIONAL', 'nodoc', 'nocompile', 'inline_doc'): |
if self.node.GetProperty(property_name): |
properties[property_name.lower()] = True |
is_function = False |
@@ -140,8 +121,7 @@ class Member(object): |
if node.cls == 'Comment': |
(parent_comment, parameter_comments) = ProcessComment(node.GetName()) |
properties['description'] = parent_comment |
- for node in self.node.children: |
- if node.cls == 'Callspec': |
+ elif node.cls == 'Callspec': |
is_function = True |
name, parameters = Callspec(node, parameter_comments).process(callbacks) |
properties['parameters'] = parameters |
@@ -151,6 +131,13 @@ class Member(object): |
else: |
properties = Typeref(self.node.GetProperty('TYPEREF'), |
self.node, properties).process(callbacks) |
+ enum_values = self.node.GetProperty('legalValues') |
+ if enum_values: |
+ if properties['type'] == 'integer': |
+ enum_values = map(int, enum_values) |
+ elif properties['type'] == 'double': |
+ enum_values = map(float, enum_values) |
+ properties['enum'] = enum_values |
return name, properties |
class Typeref(object): |
@@ -170,6 +157,8 @@ class Typeref(object): |
if self.parent.GetProperty('OPTIONAL', False): |
properties['optional'] = True |
+ if self.parent.GetProperty('inline_doc', False): |
+ properties['inline_doc'] = True |
# The IDL parser denotes array types by adding a child 'Array' node onto |
# the Param node in the Callspec. |
@@ -210,42 +199,72 @@ class Typeref(object): |
return result |
+ |
+class Enum(object): |
+ ''' |
+ Given an IDL Enum node, converts into a Python dictionary that the JSON |
+ schema compiler expects to see. |
+ ''' |
+ def __init__(self, enum_node): |
+ self.node = enum_node |
+ self.description = '' |
+ |
+ def process(self, callbacks): |
+ enum = [] |
+ for node in self.node.children: |
+ if node.cls == 'EnumItem': |
+ enum.append(node.GetName()) |
+ 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(), |
+ 'description': self.description, |
+ 'type': 'string', |
+ 'enum': enum} |
+ |
+ |
class Namespace(object): |
''' |
Given an IDLNode representing an IDL namespace, converts into a Python |
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 node.cls == 'Dictionary': |
self.types.append(Dictionary(node).process(self.callbacks)) |
- elif cls == "Callback": |
+ elif node.cls == 'Callback': |
k, v = Member(node).process(self.callbacks) |
self.callbacks[k] = v |
- elif cls == "Interface" and node.GetName() == "Functions": |
+ elif node.cls == 'Interface' and node.GetName() == 'Functions': |
self.functions = self.process_interface(node) |
- elif cls == "Interface" and node.GetName() == "Events": |
+ elif node.cls == 'Interface' and node.GetName() == 'Events': |
self.events = self.process_interface(node) |
- elif cls == "Enum": |
+ elif node.cls == 'Enum': |
self.types.append(Enum(node).process(self.callbacks)) |
+ elif node.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 +285,23 @@ 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) |
+ if node.cls == 'Namespace': |
+ namespace = Namespace(node, nodoc, permissions) |
namespaces.append(namespace.process()) |
- elif cls == 'Copyright': |
- continue |
- elif cls == 'Comment': |
+ elif node.cls in ['Copyright', 'Comment']: |
continue |
- elif cls == 'ExtAttribute': |
+ elif node.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 |