Skip to content
Snippets Groups Projects
Commit 73cead2d authored by Dennis Gläser's avatar Dennis Gläser
Browse files

[docgen][code_to_md] remove Literal() statements where possible

parent b6b12204
No related branches found
No related tags found
2 merge requests!1915Feature/modify python examples docgen,!1914[examples] Implement Python-only doc generator using pyparsing
...@@ -14,8 +14,8 @@ def parseTaggedContent(keyname, action, open="[[", close="]]", endTag="/"): ...@@ -14,8 +14,8 @@ def parseTaggedContent(keyname, action, open="[[", close="]]", endTag="/"):
""" """
Match content between [[keyname]] and [[/keyname]] and apply the action on it Match content between [[keyname]] and [[/keyname]] and apply the action on it
""" """
start = LineStart() + ZeroOrMore(" ") + Literal("//") + ZeroOrMore(" ") + Literal(open + str(keyname) + close) start = LineStart() + ZeroOrMore(" ") + "//" + ZeroOrMore(" ") + Literal(open + str(keyname) + close)
end = LineStart() + ZeroOrMore(" ") + Literal("//") + ZeroOrMore(" ") + Literal(open + endTag + str(keyname) + close) end = LineStart() + ZeroOrMore(" ") + "//" + ZeroOrMore(" ") + Literal(open + endTag + str(keyname) + close)
return start.suppress() + SkipTo(end).setParseAction(action) + end.suppress() return start.suppress() + SkipTo(end).setParseAction(action) + end.suppress()
def createMarkdownCode(markDownToken): def createMarkdownCode(markDownToken):
...@@ -34,17 +34,17 @@ def cppRules(): ...@@ -34,17 +34,17 @@ def cppRules():
""" """
Define a list of rules to apply for cpp source code Define a list of rules to apply for cpp source code
""" """
header = Suppress(Combine(Literal("// -*-") + SkipTo(Literal("*******/") + LineEnd()) + Literal("*******/"))) header = Suppress(Combine("// -*-" + SkipTo("*******/" + LineEnd()) + "*******/"))
headerGuard = Suppress(Literal("#ifndef") + Optional(restOfLine) + LineEnd() + Literal("#define") + Optional(restOfLine)) headerGuard = Suppress("#ifndef" + Optional(restOfLine) + LineEnd() + "#define" + Optional(restOfLine))
endHeaderGuard = Suppress(Literal("#endif") + Optional(restOfLine)) endHeaderGuard = Suppress("#endif" + Optional(restOfLine))
# make a code block (possibly containing comments) between [[codeblock]] and [[/codeblock]] # make a code block (possibly containing comments) between [[codeblock]] and [[/codeblock]]
action = createMarkdownCode("cpp") action = createMarkdownCode("cpp")
codeblock = parseTaggedContent("codeblock", action=action) codeblock = parseTaggedContent("codeblock", action=action)
# treat doc and code line # treat doc and code line
doc = LineStart() + Suppress(ZeroOrMore(" ") + Literal("//") + ZeroOrMore(" ")) + Optional(restOfLine) doc = LineStart() + Suppress(ZeroOrMore(" ") + "//" + ZeroOrMore(" ")) + Optional(restOfLine)
code = LineStart() + ~(ZeroOrMore(" ") + Literal("//")) + (SkipTo(doc) | SkipTo(StringEnd())) code = LineStart() + ~(ZeroOrMore(" ") + "//") + (SkipTo(doc) | SkipTo(StringEnd()))
code.setParseAction(action) code.setParseAction(action)
docTransforms = codeblock | doc | code docTransforms = codeblock | doc | code
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment