diff --git a/README.md b/README.md index bfff072..f470610 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # J Literate Programming -* [Source](https://git.jdb-labs.com/jdb-labs/jlp) +* [Source](https://git.jdb-labs.com/jdb-labs/jlp) * [Annotated Source and Documentation](https://doc.jdb-labs.com/jlp/current/) ## Overview diff --git a/build.gradle b/build.gradle index 8c92e7c..69bf072 100644 --- a/build.gradle +++ b/build.gradle @@ -2,26 +2,25 @@ apply plugin: "groovy" apply plugin: "maven" group = "com.jdblabs" -version = "1.9" +version = "1.10" repositories { mavenLocal() mavenCentral() } dependencies { - compile 'org.codehaus.groovy:groovy-all:2.3.6' - compile 'org.pegdown:pegdown:1.4.2' - compile 'org.slf4j:slf4j-api:1.7.10' - compile 'ch.qos.logback:logback-core:1.1.2' - compile 'ch.qos.logback:logback-classic:1.1.2' - compile 'commons-cli:commons-cli:1.2' - compile 'org.apache.commons:commons-lang3:3.3.2' - compile 'com.jdbernard:jdb-util:3.4' - compile 'org.pegdown:pegdown:1.4.2' + compile 'org.codehaus.groovy:groovy-all:[2.4.0,)' + compile 'org.pegdown:pegdown:[1.6.0,)' + compile 'org.slf4j:slf4j-api:[1.7.10,)' + compile 'ch.qos.logback:logback-core:[1.1.2,)' + compile 'ch.qos.logback:logback-classic:[1.1.2,)' + compile 'commons-cli:commons-cli:[1.2,)' + compile 'org.apache.commons:commons-lang3:[3.3.2,)' + compile 'com.jdbernard:jdb-util:[4.0,)' } jar { manifest { - attributes("Main-Class": "com.jdbernard.remindme.DailyAgenda") + attributes("Main-Class": "com.jdblabs.jlp.JLPMain") } } diff --git a/src/main/groovy/com/jdblabs/jlp/JLPMain.groovy b/src/main/groovy/com/jdblabs/jlp/JLPMain.groovy index d816d5c..159ae59 100644 --- a/src/main/groovy/com/jdblabs/jlp/JLPMain.groovy +++ b/src/main/groovy/com/jdblabs/jlp/JLPMain.groovy @@ -19,7 +19,7 @@ import org.slf4j.LoggerFactory */ public class JLPMain { - public static final String VERSION = "1.9" + public static final String VERSION = "1.10" private static Logger log = LoggerFactory.getLogger(JLPMain.class) @@ -113,7 +113,7 @@ public class JLPMain { /// Resolve the file against our relative root. if (!cssFile.isAbsolute()) { cssFile = new File(pathRoot, cssFile.path) } - + /// Finally, make sure the CSS file actually exists. if (cssFile.exists()) { css = cssFile @@ -142,14 +142,14 @@ public class JLPMain { /// For each filename we try to resolve it to an actual file /// relative to our root. File file = new File(filename) - if (!file.isAbsolute()) { file = new File(pathRoot, filename) } + if (!file.isAbsolute()) { file = new File(pathRoot, filename) } /// 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, we want to add all the files in it /// to our input list, recursing into all the subdirectories and /// adding their files as well. We will ignore hidden files. diff --git a/src/main/groovy/com/jdblabs/jlp/JLPPegParser.java b/src/main/groovy/com/jdblabs/jlp/JLPPegParser.java index 14e4a65..dcbe3b9 100644 --- a/src/main/groovy/com/jdblabs/jlp/JLPPegParser.java +++ b/src/main/groovy/com/jdblabs/jlp/JLPPegParser.java @@ -124,7 +124,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { public Rule SourceFile() { return Sequence( /// At the start of processing a new SourceFile, we need to set up - /// our internal state. + /// our internal state. /// Clear the line count. clearLineCount(), @@ -139,7 +139,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { FirstOf( /// Match a whole Block. This pushes a Block on the stack. - Block(), + Block(), /// A standalone DocBlock. We will create an empty CodeBlock /// to pair with it, then push a new Block onto the stack @@ -218,7 +218,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { Rule DocBlock() { return FirstOf(SDocBlock(), MDocBlock()); } /** - * #### SDocBlock + * #### SDocBlock * Parses the rule: * * SDocBlock = (SDirective / SDocText)+ @@ -235,7 +235,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { addToDocBlock((ASTNode) pop())))); } /** - * #### MDocBlock + * #### MDocBlock * Parses the rule: * * MDocBlock = MDOC_START (MDirective / MDocText)+ MDOC_END @@ -257,7 +257,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { addToDocBlock((ASTNode) pop()))), MDOC_END); } /** - * #### CodeBlock + * #### CodeBlock * Parses the rule: * * CodeBlock = (RemainingCodeLine)+ @@ -273,7 +273,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { addToCodeBlock(match())))); } /** - * #### SDirective + * #### SDirective * Parses the rule: * * SDirective = SDocLineStart AT (SLongDirective / SShortDirective) @@ -287,7 +287,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { SDocLineStart(), AT, FirstOf(SLongDirective(), SShortDirective())); } /** - * #### MDirective + * #### MDirective * Parses the rule: * * MDirective = MDocLineStart? AT (MLongDirective / MShortDirective) @@ -302,7 +302,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { AT, FirstOf(MLongDirective(), MShortDirective())); } /** - * #### SLongDirective + * #### SLongDirective * Parses the rule: * * SLongDirective = @@ -323,15 +323,15 @@ public class JLPPegParser extends BaseParser implements JLPParser { SDocText(), swap(), push(popAsString() + ((DocText) pop()).value))), - + push(new Directive(popAsString(), popAsString(), popAsInt(), (DocBlock)peek()))); } /** - * #### MLongDirective + * #### MLongDirective * Parses the rule: * - * MLongDirective = + * MLongDirective = * (API_DIR / EXAMPLE_DIR / PARAM_DIR) RemainingMDocLine MDocText? * * Pushes a [`Directive`] node onto the stack. @@ -354,7 +354,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { (DocBlock) peek()))); } /** - * #### SShortDirective + * #### SShortDirective * Parses the rule: * * SShortDirective = @@ -370,12 +370,12 @@ public class JLPPegParser extends BaseParser implements JLPParser { push(curLineNum), FirstOf(AUTHOR_DIR, ORG_DIR, INCLUDE_DIR, COPYRIGHT_DIR), push(match()), RemainingSDocLine(), - + push(new Directive(match().trim(), popAsString(), popAsInt(), (DocBlock) peek()))); } /** - * #### MShortDirective + * #### MShortDirective * Parses the rule: * * MShortDirective = @@ -396,7 +396,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { (DocBlock) peek()))); } /** - * #### SDocText + * #### SDocText * Parses the rule: * * SDocText = (SDocLineStart !AT RemainingSDocLine)+ @@ -413,7 +413,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { addToDocText(match())))); } /** - * #### MDocText + * #### MDocText * Parses the rule: * * MDocText = (MDocLineStart? !AT RemainingMDocLine)+ @@ -431,7 +431,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { addToDocText(match())))); } /** - * #### SDocLineStart + * #### SDocLineStart * Parses the rule: * * SDocLineStart = SPACE* SDOC_START SPACE? @@ -441,7 +441,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { ZeroOrMore(SPACE), SDOC_START, Optional(SPACE)); } /** - * #### MDocLineStart + * #### MDocLineStart * Parses the rule: * * MDocLineStart = SPACE* !MDOC_END MDOC_LINE_START SPACE? @@ -451,7 +451,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { ZeroOrMore(SPACE), TestNot(MDOC_END), MDOC_LINE_START, Optional(SPACE)); } /** - * #### RemainingSDocLine + * #### RemainingSDocLine * Parses the rule: * * RemainingSDocLine = ((!EOL)* EOL) / ((!EOL)+ EOI) @@ -462,10 +462,10 @@ public class JLPPegParser extends BaseParser implements JLPParser { Sequence(OneOrMore(NOT_EOL), EOI, incLineCount())); } /** - * #### RemainingMDocLine + * #### RemainingMDocLine * Parses the rule: * - * RemainingMDocLine = + * RemainingMDocLine = * ((!(EOL / MDOC_END))* EOL) / * ((!MDOC_END)+) */ @@ -481,10 +481,10 @@ public class JLPPegParser extends BaseParser implements JLPParser { OneOrMore(Sequence(TestNot(MDOC_END), ANY))); } /** - * #### RemainingCodeLine + * #### RemainingCodeLine * Parses the rule: * - * RemainingCodeLine = + * RemainingCodeLine = * ((!(EOL / MDOC_START / SDocLineStart))* EOL) / * (!(MDOC_START / SDocLineStart))+ */ @@ -565,7 +565,7 @@ public class JLPPegParser extends BaseParser implements JLPParser { docBlock.docTexts.add((DocText) an); } else { throw new IllegalStateException(); } return push(docBlock); } - + boolean addToCodeBlock(String line) { CodeBlock codeBlock = (CodeBlock) pop(); codeBlock.lines.put(curLineNum - 1, line); diff --git a/src/main/groovy/com/jdblabs/jlp/Processor.groovy b/src/main/groovy/com/jdblabs/jlp/Processor.groovy index 280ad75..b93c35f 100644 --- a/src/main/groovy/com/jdblabs/jlp/Processor.groovy +++ b/src/main/groovy/com/jdblabs/jlp/Processor.groovy @@ -125,7 +125,7 @@ public class Processor { /// is more than one file with the same name we will include the /// file's parent directory as well. inputFiles.each { file -> - + // Get the relative path as path elements. def relPath = getRelativeFilepath(inputRoot, file) def pathParts = relPath.split('/|\\\\') as List @@ -160,7 +160,7 @@ public class Processor { // TODO: better error detection and handling currentDoc.sourceAST = parser.parse(currentDoc.sourceFile.text) - + if (currentDoc.sourceAST == null) { log.warn("Unable to parse '{}'. Ignoring this document.", currentDocId) badDocs << currentDocId }} @@ -186,7 +186,7 @@ public class Processor { /// * Write the output to the output directory. processDocs { - + /// Create the path and file object for the output file String relativePath = getRelativeFilepath(inputRoot, currentDoc.sourceFile) @@ -238,7 +238,7 @@ public class Processor { * : Return the link as-is. * * *absolute path (starts with `/`)* - * : Returns the link resolved against the output root. + * : Returns the link resolved against the output root. * * *relative path (no leading `/`)* * : Returns the link resolved against the `TargetDoc` passed in. @@ -281,12 +281,12 @@ public class Processor { case ~/^\w+:.*/: return link /// Absolute link, resolve relative to the output root. - case ~/^\/.*/: + case ~/^\/.*/: /// Our link should be the relative path (if needed) plus the /// link without the leading `/`. def relPath = getRelativeFilepath(targetDoc.sourceFile, inputRoot) return (relPath ? "${relPath}/" : "") + link[1..-1] - + /// Relative link, resolve using the output root and the source /// document relative to the input root. default: @@ -295,7 +295,7 @@ public class Processor { /** * #### getRelativeFilepath - * Assuming our current directory is `root`, get the relative path to + * Assuming our current directory is `root`, get the relative path to * `file`. * @org jlp.jdb-labs.com/Processor/getRelativeFilepath */ @@ -329,7 +329,7 @@ public class Processor { * #### getCommonParent * Find the common parent directory to the given files. * @org jlp.jdb-labs.com/Processor/getCommonParent - */ + */ public static File getCommonParent(File file1, File file2) { def path1 = file1.canonicalPath.split('/|\\\\') def path2 = file2.canonicalPath.split('/|\\\\') @@ -339,7 +339,7 @@ public class Processor { int i = 0 while (i < Math.min(path1.length, path2.length) && path1[i] == path2[i]) { - + newPath << path2[i] i++ }