Sorting out Parboiled issues. Initial parser draft complete.
* Created test script. * Created working parser.
This commit is contained in:
parent
303f8839fd
commit
e8ebcd4998
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
build/
|
||||
.*.sw?
|
BIN
lib/compile/jar/parboiled-java-1.0.1.jar
Normal file
BIN
lib/compile/jar/parboiled-java-1.0.1.jar
Normal file
Binary file not shown.
BIN
lib/runtime/jar/asm-all-3.3.1.jar
Normal file
BIN
lib/runtime/jar/asm-all-3.3.1.jar
Normal file
Binary file not shown.
BIN
lib/runtime/jar/parboiled-java-1.0.1.jar
Normal file
BIN
lib/runtime/jar/parboiled-java-1.0.1.jar
Normal file
Binary file not shown.
21
resources/main/test.groovy
Normal file
21
resources/main/test.groovy
Normal file
@ -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)
|
@ -1,19 +0,0 @@
|
||||
package com.jdblabs.jlp
|
||||
|
||||
@BuildParseTree
|
||||
public class JLPPegParser extends BaseParser<Object> {
|
||||
|
||||
Rule CodePage() {
|
||||
return ZeroOrMore(FirstOf(
|
||||
DocBlock(),
|
||||
CodeBlock())) }
|
||||
|
||||
Rule DocBlock() {
|
||||
return OneOrMore(FirstOf(
|
||||
DirectiveBlock(),
|
||||
MarkdownBlock())) }
|
||||
|
||||
Rule DirectiveBlock() {
|
||||
return FirstOf(
|
||||
Sequence("%% "
|
||||
}
|
@ -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 ->
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
62
src/main/com/jdblabs/jlp/JLPPegParser.groovy
Normal file
62
src/main/com/jdblabs/jlp/JLPPegParser.groovy
Normal file
@ -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<Object> {
|
||||
|
||||
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")
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user