Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(59)

Unified Diff: tools/json_schema_compiler/idl_schema.py

Issue 10082038: Hack together a quick doc generator for IDL files. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/common/extensions/docs/samples.json ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 1d3c83ae3b9652767c0f73ec4e56601d8e2b933c..70ed9edb5fa2c967a482cdd20b8d69375c453228 100644
--- a/tools/json_schema_compiler/idl_schema.py
+++ b/tools/json_schema_compiler/idl_schema.py
@@ -4,6 +4,7 @@
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
@@ -20,18 +21,42 @@ 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 dictionary that looks
+ like:
+ {
+ '': "The processed comment, minus all |parameter| mentions.",
asargent_no_longer_on_chrome 2012/04/16 17:34:11 nit: using the empty string as a key makes the cod
Matt Perry 2012/04/16 19:19:15 I had it return a tuple of (summary_comment, parse
+ '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 = {'': parent_comment}
+ for (name, comment) in parameter_comments:
+ parsed[name] = comment.replace('\n', '').strip()
+ return 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, refs):
parameters = []
for node in self.node.children:
- parameters.append(Param(node).process(refs))
+ parameter = Param(node).process(refs)
+ if parameter['name'] in self.comment:
+ parameter['description'] = self.comment[parameter['name']]
+ parameters.append(parameter)
return self.node.GetName(), parameters
class Param(object):
@@ -82,10 +107,15 @@ class Member(object):
if self.node.GetProperty('nodoc'):
properties['nodoc'] = True
is_function = False
+ comment = {}
+ for node in self.node.children:
+ if node.cls == 'Comment':
+ comment = ProcessComment(node.GetName())
+ properties['description'] = comment['']
for node in self.node.children:
if node.cls == 'Callspec':
is_function = True
- name, parameters = Callspec(node).process(refs)
+ name, parameters = Callspec(node, comment).process(refs)
properties['parameters'] = parameters
properties['name'] = name
if is_function:
« no previous file with comments | « chrome/common/extensions/docs/samples.json ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698