aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2010-07-31 15:49:59 -0400
committerbnewbold <bnewbold@robocracy.org>2010-07-31 15:49:59 -0400
commit2252d2dcc983f5811b0eab1449af8392491b864e (patch)
treee481369a0731d5eccd4fbf3e192f118521c9a683
parent0e64b7c0933a1993dc3d31770c1550cea4d10f04 (diff)
downloadpycco-master.tar.gz
pycco-master.zip
BROKEN: partial implementation of C versionHEADmaster
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-xpycco27
1 files changed, 23 insertions, 4 deletions
diff --git a/pycco b/pycco
index e9a4866..7a17a11 100755
--- a/pycco
+++ b/pycco
@@ -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.