summaryrefslogtreecommitdiffstats
path: root/tools/json_schema_compiler/idl_schema.py
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 22:11:28 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-16 22:11:28 +0000
commitd6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1 (patch)
treeeea521d18b304ace5eb9054000dfe6ec3c79d308 /tools/json_schema_compiler/idl_schema.py
parentbf0fa4274346304e3ba8d8072e24038004c39ef3 (diff)
downloadchromium_src-d6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1.zip
chromium_src-d6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1.tar.gz
chromium_src-d6bad8d5c7c2882f9ca62e70bef3d9ea60a10ca1.tar.bz2
Hack together a quick doc generator for IDL files.
- Changed the IDL parser to mine the Comment nodes, and process them for parameter comments. - Added hacks to the doc builder to parse the IDL files and spit out a generated JSON file before running the generator. BUG=no TEST=no Review URL: https://chromiumcodereview.appspot.com/10082038 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@132474 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/json_schema_compiler/idl_schema.py')
-rw-r--r--[-rwxr-xr-x]tools/json_schema_compiler/idl_schema.py39
1 files changed, 36 insertions, 3 deletions
diff --git a/tools/json_schema_compiler/idl_schema.py b/tools/json_schema_compiler/idl_schema.py
index 8d735e8..3a7e6e4 100755..100644
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -6,6 +6,7 @@
import json
import os.path
import sys
+import re
# This file is a peer to json_schema.py. Each of these files understands a
# certain format describing APIs (either JSON or IDL), reads files written
@@ -22,18 +23,45 @@ if idl_generators_path not in sys.path:
sys.path.insert(0, idl_generators_path)
import idl_parser
+def ProcessComment(comment):
+ '''
+ Given the string from a Comment node, parse it into a tuple that looks
+ like:
+ (
+ "The processed comment, minus all |parameter| mentions.",
+ {
+ 'parameter_name_1': "The comment that followed |parameter_name_1|:",
+ ...
+ }
+ )
+ '''
+ # 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)
+ parent_comment = parent_comment.replace('\n', '').strip()
+
+ parsed = {}
+ for (name, comment) in parameter_comments:
+ parsed[name] = comment.replace('\n', '').strip()
+ return (parent_comment, parsed)
+
class Callspec(object):
'''
Given a Callspec node representing an IDL function declaration, converts into
a name/value pair where the value is a list of function parameters.
'''
- def __init__(self, callspec_node):
+ def __init__(self, callspec_node, comment):
self.node = callspec_node
+ self.comment = comment
def process(self, callbacks):
parameters = []
for node in self.node.children:
- parameters.append(Param(node).process(callbacks))
+ parameter = Param(node).process(callbacks)
+ if parameter['name'] in self.comment:
+ parameter['description'] = self.comment[parameter['name']]
+ parameters.append(parameter)
return self.node.GetName(), parameters
class Param(object):
@@ -84,10 +112,15 @@ class Member(object):
if self.node.GetProperty('nodoc'):
properties['nodoc'] = True
is_function = False
+ parameter_comments = {}
+ for node in self.node.children:
+ 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':
is_function = True
- name, parameters = Callspec(node).process(callbacks)
+ name, parameters = Callspec(node, parameter_comments).process(callbacks)
properties['parameters'] = parameters
properties['name'] = name
if is_function: