diff options
author | bnewbold <bnewbold@robocracy.org> | 2010-07-31 15:49:59 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2010-07-31 15:49:59 -0400 |
commit | 2252d2dcc983f5811b0eab1449af8392491b864e (patch) | |
tree | e481369a0731d5eccd4fbf3e192f118521c9a683 | |
parent | 0e64b7c0933a1993dc3d31770c1550cea4d10f04 (diff) | |
download | pycco-master.tar.gz pycco-master.zip |
Uses a "preparsing" step that turns /*blah*/-style comment blocks
into //-style blocks. Very buggy.
Does not currently catch "end of line" //-style comments.
-rwxr-xr-x | pycco | 27 |
1 files changed, 23 insertions, 4 deletions
@@ -27,11 +27,29 @@ # and merging them into an HTML template. def generate_documentation(source): fh = open(source, "r") - sections = parse(source, fh.read()) + sections = parse(source, preparse(fh.read())) highlight(source, sections) generate_html(source, sections) +license_header = """// This code is under the XYZ License"""; + +# Preparse /*blah*/-style comments into //-style comments +def preparse(code): + c = re.compile('(/\*.*?\*/)', re.DOTALL) + d = re.compile('^\s?([ \t\*]+?)', re.MULTILINE) + l = [] + for block in c.split(code): + if(block.count("THE SOFTWARE IS PROVIDED")): + l.append(license_header); + elif(block.strip().startswith("/*")): + print [block, d.sub(r'// ', block.strip()[2:-2])] + l.append(d.sub(r'// ', block.strip()[2:-2])) + else: + l.append(block) + + return "".join(l) + # Given a string of source code, parse out each comment and the code that # follows it, and create an individual **section** for it. # Sections take the form: @@ -127,12 +145,13 @@ from subprocess import Popen, PIPE # the name of the Pygments lexer and the symbol that indicates a comment. To # add another language to Pycco's repertoire, add it here. languages = { - ".coffee": { "name": "coffee-script", "symbol": "#" }, + #".coffee": { "name": "coffee-script", "symbol": "#" }, ".js": { "name": "javascript", "symbol": "//" }, ".rb": { "name": "ruby", "symbol": "#" }, ".py": { "name": "python", "symbol": "#" }, - ".scm": { "name": "scheme", "symbol": ";;" }, - ".lua": { "name": "lua", "symbol": "--" }, + #".scm": { "name": "scheme", "symbol": ";;" }, + #".lua": { "name": "lua", "symbol": "--" }, + ".c": { "name": "c", "symbol": "//"}, } # Build out the appropriate matchers and delimiters for each language. |