diff --git a/build.xml b/build.xml index e2bdb1e..087350a 100644 --- a/build.xml +++ b/build.xml @@ -1,13 +1,20 @@ - + + - + + + + + + + diff --git a/jdb-build-1.6.xml b/jdb-build-1.9.xml similarity index 77% rename from jdb-build-1.6.xml rename to jdb-build-1.9.xml index 3a43212..9f92c4f 100644 --- a/jdb-build-1.6.xml +++ b/jdb-build-1.9.xml @@ -1,5 +1,6 @@ - + @@ -16,6 +17,7 @@ + @@ -59,9 +61,25 @@ - + + + - + + + + + + + + + + + + + @@ -96,7 +114,7 @@ - + @@ -109,7 +127,7 @@ - + @@ -178,13 +196,42 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/project.properties b/project.properties index 7b363f1..4b2228b 100644 --- a/project.properties +++ b/project.properties @@ -1,6 +1,8 @@ -#Sun, 25 Dec 2011 21:56:17 -0600 +#Sun, 25 Dec 2011 23:07:02 -0600 name=jlp -version=1.0 -build.number=0 +version=1.1 +build.number=6 lib.local=true release.dir=release +main.class=com.jdblabs.jlp.JLPMain +executable.jar=true diff --git a/jlp b/resources/release/jlp similarity index 100% rename from jlp rename to resources/release/jlp diff --git a/src/main/com/jdblabs/jlp/JLPMain.groovy b/src/main/com/jdblabs/jlp/JLPMain.groovy index 97742c7..d832121 100644 --- a/src/main/com/jdblabs/jlp/JLPMain.groovy +++ b/src/main/com/jdblabs/jlp/JLPMain.groovy @@ -73,19 +73,27 @@ public class JLPMain { // get files passed in def filenames = opts.getArgs() - def inputFiles = (filenames.collect { filename -> + def inputFiles = [] + + filenames.each { filename -> // create a File object - File file = new File(filename) - + File file = new File(filename) + // if this is a relative path, resolve it against our path root if (!file.isAbsolute()) { file = new File(pathRoot, filename) } - - // warn the user about files that do not exist - if (!file.exists()) { - System.err.println - "'${file.canonicalPath}' does not exist: ignored." } - return file }).findAll { it.exists() } + // if this file does not exist, warn the user and skip it + if (!file.exists()) { + System.err.println( + "'${file.canonicalPath}' does not exist: ignored.") + return } + + // if this file is a directory, add all the files in it (recurse + // into sub-directories and add their contents as well). + if (file.isDirectory()) { file.eachFileRecurse { + if (it.isFile()) { inputFiles << it }}} + + else { inputFiles << file } } Processor.process(outputDir, css, inputFiles) } diff --git a/src/main/com/jdblabs/jlp/JLPParser.java b/src/main/com/jdblabs/jlp/JLPParser.java new file mode 100644 index 0000000..bc27efa --- /dev/null +++ b/src/main/com/jdblabs/jlp/JLPParser.java @@ -0,0 +1,6 @@ +package com.jdblabs.jlp; + +import com.jdblabs.jlp.ast.SourceFile; + +public interface JLPParser { + public SourceFile parse(String input); } diff --git a/src/main/com/jdblabs/jlp/JLPPegParser.java b/src/main/com/jdblabs/jlp/JLPPegParser.java index 79d54a9..c80644a 100644 --- a/src/main/com/jdblabs/jlp/JLPPegParser.java +++ b/src/main/com/jdblabs/jlp/JLPPegParser.java @@ -8,9 +8,10 @@ import org.parboiled.BaseParser; import org.parboiled.Context; import org.parboiled.Rule; import org.parboiled.annotations.*; +import org.parboiled.parserunners.ReportingParseRunner; @BuildParseTree -public class JLPPegParser extends BaseParser { +public class JLPPegParser extends BaseParser implements JLPParser { int curLineNum = 1; @@ -31,6 +32,10 @@ public class JLPPegParser extends BaseParser { public JLPPegParser() { this("/**", "*/", "!#$%^&*()_-=+|;:'\",<>?~`", "///"); } + public SourceFile parse(String input) { + ReportingParseRunner rpr = new ReportingParseRunner(this.SourceFile()); + return (SourceFile) rpr.run(input).resultValue; } + /** * Parses the rule: * SourceFile = (Block / DocBlock / CodeBlock)+ diff --git a/src/main/com/jdblabs/jlp/MarkdownParser.groovy b/src/main/com/jdblabs/jlp/MarkdownParser.groovy new file mode 100644 index 0000000..167cfcc --- /dev/null +++ b/src/main/com/jdblabs/jlp/MarkdownParser.groovy @@ -0,0 +1,20 @@ +package com.jdblabs.jlp + +import com.jdblabs.jlp.ast.* + +public class MarkdownParser implements JLPParser { + + public SourceFile parse(String input) { + + def sourceFile = new SourceFile() + def block + def docBlock = new DocBlock(0) + def codeBlock = new CodeBlock(0) + def docText = new DocText(0) + + docText.value = input + docBlock.docTexts << docText + block = new Block(codeBlock, docBlock, 0) + sourceFile.blocks << block + + return sourceFile }} diff --git a/src/main/com/jdblabs/jlp/Processor.groovy b/src/main/com/jdblabs/jlp/Processor.groovy index 95c922a..7b09964 100644 --- a/src/main/com/jdblabs/jlp/Processor.groovy +++ b/src/main/com/jdblabs/jlp/Processor.groovy @@ -2,7 +2,6 @@ package com.jdblabs.jlp import org.parboiled.BaseParser import org.parboiled.Parboiled -import org.parboiled.parserunners.ReportingParseRunner /** * Processor processes one batch of input files to create a set of output files. @@ -22,7 +21,7 @@ public class Processor { // shortcut for docs[currentDocId] public TargetDoc currentDoc - protected Map parsers = [:] + protected Map parsers = [:] protected Map generators = [:] public static void process(File outputDir, String css, @@ -61,11 +60,9 @@ public class Processor { // TODO: add logic to configure or autodetect the correct parser for // each file def parser = getParser(sourceTypeForFile(currentDoc.sourceFile)) - def parseRunner = new ReportingParseRunner(parser.SourceFile()) // TODO: error detection - currentDoc.sourceAST = parseRunner.run( - currentDoc.sourceFile.text).resultValue } + currentDoc.sourceAST = parser.parse(currentDoc.sourceFile.text) } // run our generator parse phase (first pass over the ASTs) processDocs { @@ -175,6 +172,7 @@ public class Processor { case 'groovy': return 'groovy'; case 'java': return 'java'; case 'js': return 'javascript'; + case 'md': return 'markdown'; default: return 'unknown'; }} protected getGenerator(String sourceType) { @@ -187,13 +185,14 @@ public class Processor { return generators[sourceType] } protected getParser(String sourceType) { - println "Looking for a ${sourceType} parser." if (parsers[sourceType] == null) { switch(sourceType) { case 'erlang': parsers[sourceType] = Parboiled.createParser( JLPPegParser, '%%') - println "Built an erlang parser." + break + case 'markdown': + parsers[sourceType] = new MarkdownParser() break case 'c': case 'c++': @@ -203,7 +202,6 @@ public class Processor { default: parsers[sourceType] = Parboiled.createParser(JLPPegParser, '/**', '*/', '!#$%^&*()_-=+|;:\'",<>?~`', '///') - println "Built a java parser." break }} return parsers[sourceType] }