diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d6f838a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +build/ +.*.sw? diff --git a/lib/compile/jar/parboiled-java-1.0.1.jar b/lib/compile/jar/parboiled-java-1.0.1.jar new file mode 100644 index 0000000..3dc7d3e Binary files /dev/null and b/lib/compile/jar/parboiled-java-1.0.1.jar differ diff --git a/lib/runtime/jar/asm-all-3.3.1.jar b/lib/runtime/jar/asm-all-3.3.1.jar new file mode 100644 index 0000000..39a0d6d Binary files /dev/null and b/lib/runtime/jar/asm-all-3.3.1.jar differ diff --git a/lib/runtime/jar/parboiled-java-1.0.1.jar b/lib/runtime/jar/parboiled-java-1.0.1.jar new file mode 100644 index 0000000..3dc7d3e Binary files /dev/null and b/lib/runtime/jar/parboiled-java-1.0.1.jar differ diff --git a/resources/main/test.groovy b/resources/main/test.groovy new file mode 100644 index 0000000..9e9b26d --- /dev/null +++ b/resources/main/test.groovy @@ -0,0 +1,21 @@ +import com.jdblabs.jlp.JLPPegParser +import org.parboiled.Parboiled +import org.parboiled.parserunners.ReportingParseRunner +import org.parboiled.parserunners.RecoveringParseRunner + +parser = Parboiled.createParser(JLPPegParser.class) +parseRunner = new RecoveringParseRunner(parser.CodePage()) + +testLine = """%% This the first test line. +%% Second Line +%% Third Line +Fourth line +%% Fifth line +%% @author Sixth Line +%% @Example Seventh Line +%% Markdown lines (eigth line) +%% Still markdown (ninth line) +Tenth line is a code line +""" + +result = parseRunner.run(testLine) diff --git a/src/com/jdblabs/jlp/JLPPegParser.groovy b/src/com/jdblabs/jlp/JLPPegParser.groovy deleted file mode 100644 index 1169f19..0000000 --- a/src/com/jdblabs/jlp/JLPPegParser.groovy +++ /dev/null @@ -1,19 +0,0 @@ -package com.jdblabs.jlp - -@BuildParseTree -public class JLPPegParser extends BaseParser { - - Rule CodePage() { - return ZeroOrMore(FirstOf( - DocBlock(), - CodeBlock())) } - - Rule DocBlock() { - return OneOrMore(FirstOf( - DirectiveBlock(), - MarkdownBlock())) } - - Rule DirectiveBlock() { - return FirstOf( - Sequence("%% " -} diff --git a/src/com/jdblabs/jlp/JLPMain.groovy b/src/main/com/jdblabs/jlp/JLPMain.groovy similarity index 70% rename from src/com/jdblabs/jlp/JLPMain.groovy rename to src/main/com/jdblabs/jlp/JLPMain.groovy index f0a43d7..9a17f9e 100644 --- a/src/com/jdblabs/jlp/JLPMain.groovy +++ b/src/main/com/jdblabs/jlp/JLPMain.groovy @@ -2,7 +2,7 @@ package com.jdblabs.jlp public class JLPMain { - public static void main(String args[]) { + public static void main(String[] args) { JLPMain inst = new JLPMain() @@ -25,7 +25,7 @@ public class JLPMain { // get files passed in def filenames = opts.getArgs() - def files = filenames.collect { new File(if) } + def files = filenames.collect { new File(it) } // -------- parse input -------- // files.inject(documentContext) { docContext, file -> @@ -35,17 +35,6 @@ public class JLPMain { } public void parse(File inputFile, Map docCtx) { - def currentDocBlock - def thisDoc = [ blocks:[] ] - - String docName = inputFile.name.substring( - 0, inputFile.name.lastIndexOf('.')) - - docCtx.docs[docName] = thisDoc - - inputFile.eachLine { line, lineNum -> - - } } } diff --git a/src/main/com/jdblabs/jlp/JLPPegParser.groovy b/src/main/com/jdblabs/jlp/JLPPegParser.groovy new file mode 100644 index 0000000..0cec44b --- /dev/null +++ b/src/main/com/jdblabs/jlp/JLPPegParser.groovy @@ -0,0 +1,62 @@ +package com.jdblabs.jlp + +import org.parboiled.BaseParser +import org.parboiled.Rule +import org.parboiled.annotations.* + +public class JLPPegParser extends BaseParser { + + public Rule CodePage() { + println "Parsing CodePage" + ZeroOrMore(FirstOf( + DocBlock(), + CodeBlock())) } + + Rule DocBlock() { + OneOrMore(FirstOf( + DirectiveBlock(), + MarkdownBlock())) } + + Rule CodeBlock() { + OneOrMore(Sequence( + TestNot(DOC_START), RemainingLine())) } + + Rule DirectiveBlock() { + FirstOf( + + // there is a bug in parboiled that prevents sequences of greater + // than 2, so this ia workaround + Sequence( + Sequence( + Sequence(DOC_START, DIRECTIVE_START), + Sequence(LongDirective(), RemainingLine())), + Sequence(Optional(MarkdownBlock()))), + + Sequence( + Sequence(DOC_START, DIRECTIVE_START), + Sequence(LineDirective(), RemainingLine()))) } + + Rule LongDirective() { FirstOf(AUTHOR_DIR, DOC_DIR, EXAMPLE_DIR) } + + Rule LineDirective() { ORG_DIR } + + Rule MarkdownBlock() { OneOrMore(MarkdownLine()) } + + Rule MarkdownLine() { + Sequence(DOC_START, Sequence(TestNot(DIRECTIVE_START), RemainingLine())) } + + Rule RemainingLine() { Sequence(OneOrMore(NOT_EOL), EOL) } + + Rule DOC_START = String("%% ") + Rule EOL = Ch('\n' as char) + Rule NOT_EOL = Sequence(TestNot(EOL), ANY) + Rule DIRECTIVE_START= Ch('@' as char) + Rule SLASH = Ch('/' as char) + + // directive terminals + Rule AUTHOR_DIR = IgnoreCase("author") + Rule DOC_DIR = IgnoreCase("doc") + Rule EXAMPLE_DIR = IgnoreCase("example") + Rule ORG_DIR = IgnoreCase("org") + +}