}
)
'''
+ def add_paragraphs(content):
+ paragraphs = content.split('\n\n')
+ if len(paragraphs) < 2:
+ return content
+ return '<p>' + '</p><p>'.join(p.strip() for p in paragraphs) + '</p>'
+
# Find all the parameter comments of the form '|name|: comment'.
parameter_starts = list(re.finditer(r' *\|([^|]*)\| *: *', comment))
# Get the parent comment (everything before the first parameter comment.
first_parameter_location = (parameter_starts[0].start()
if parameter_starts else len(comment))
- parent_comment = comment[:first_parameter_location]
-
- # We replace \n\n with <br/><br/> here and below, because the documentation
- # needs to know where the newlines should be, and this is easier than
- # escaping \n.
- parent_comment = (parent_comment.strip().replace('\n\n', '<br/><br/>')
- .replace('\n', ''))
+ parent_comment = (add_paragraphs(comment[:first_parameter_location].strip())
+ .replace('\n', ''))
params = OrderedDict()
for (cur_param, next_param) in itertools.izip_longest(parameter_starts,
# beginning of the next parameter's introduction.
param_comment_start = cur_param.end()
param_comment_end = next_param.start() if next_param else len(comment)
- params[param_name] = (comment[param_comment_start:param_comment_end
- ].strip().replace('\n\n', '<br/><br/>')
- .replace('\n', ''))
+ params[param_name] = (
+ add_paragraphs(comment[param_comment_start:param_comment_end].strip())
+ .replace('\n', ''))
+
return (parent_comment, params)
result = {'id': self.node.GetName(),
'properties': properties,
'type': 'object'}
- if self.node.GetProperty('inline_doc'):
+ if self.node.GetProperty('nodoc'):
+ result['nodoc'] = True
+ elif self.node.GetProperty('inline_doc'):
result['inline_doc'] = True
elif self.node.GetProperty('noinline_doc'):
result['noinline_doc'] = True
name = self.node.GetName()
if self.node.GetProperty('deprecated'):
properties['deprecated'] = self.node.GetProperty('deprecated')
+ if self.node.GetProperty('allowAmbiguousOptionalArguments'):
+ properties['allowAmbiguousOptionalArguments'] = True
for property_name in ('OPTIONAL', 'nodoc', 'nocompile', 'nodart'):
if self.node.GetProperty(property_name):
properties[property_name.lower()] = True
function parameter, converts into a Python dictionary that the JSON schema
compiler expects to see.
'''
- def __init__(self, typeref, parent, additional_properties=OrderedDict()):
+ def __init__(self, typeref, parent, additional_properties):
self.typeref = typeref
self.parent = parent
self.additional_properties = additional_properties
properties = self.additional_properties
result = properties
- if self.parent.GetProperty('OPTIONAL'):
+ if self.parent.GetPropertyLocal('OPTIONAL'):
properties['optional'] = True
# The IDL parser denotes array types by adding a child 'Array' node onto
if 'additionalProperties' not in properties:
properties['additionalProperties'] = OrderedDict()
properties['additionalProperties']['type'] = 'any'
+ elif self.parent.GetPropertyLocal('Union'):
+ choices = []
+ properties['choices'] = [Typeref(node.GetProperty('TYPEREF'),
+ node,
+ OrderedDict()).process(callbacks)
+ for node in self.parent.GetChildren()
+ if node.cls == 'Option']
elif self.typeref is None:
properties['type'] = 'function'
else:
'description': self.description,
'type': 'string',
'enum': enum}
- for property_name in ('inline_doc', 'noinline_doc', 'nodoc'):
+ for property_name in (
+ 'inline_doc', 'noinline_doc', 'nodoc', 'cpp_enum_prefix_override',):
if self.node.GetProperty(property_name):
- result[property_name] = True
+ result[property_name] = self.node.GetProperty(property_name)
if self.node.GetProperty('deprecated'):
result[deprecated] = self.node.GetProperty('deprecated')
return result
internal = False
description = None
platforms = None
- compiler_options = None
+ compiler_options = {}
deprecated = None
for node in self.idl:
if node.cls == 'Namespace':
description = ''
namespace = Namespace(node, description, nodoc, internal,
platforms=platforms,
- compiler_options=compiler_options,
+ compiler_options=compiler_options or None,
deprecated=deprecated)
namespaces.append(namespace.process())
nodoc = False
elif node.name == 'platforms':
platforms = list(node.value)
elif node.name == 'implemented_in':
- compiler_options = {'implemented_in': node.value}
+ compiler_options['implemented_in'] = node.value
+ elif node.name == 'camel_case_enum_to_string':
+ compiler_options['camel_case_enum_to_string'] = node.value
elif node.name == 'deprecated':
deprecated = str(node.value)
else:
Dump a json serialization of parse result for the IDL files whose names
were passed in on the command line.
'''
- for filename in sys.argv[1:]:
- schema = Load(filename)
+ if len(sys.argv) > 1:
+ for filename in sys.argv[1:]:
+ schema = Load(filename)
+ print json.dumps(schema, indent=2)
+ else:
+ contents = sys.stdin.read()
+ idl = idl_parser.IDLParser().ParseData(contents, '<stdin>')
+ schema = IDLSchema(idl).process()
print json.dumps(schema, indent=2)