2011-08-31 14:46:25 +00:00
|
|
|
import com.jdblabs.jlp.*
|
2011-09-06 21:13:21 +00:00
|
|
|
import com.jdblabs.jlp.experimental.LiterateMarkdownGenerator
|
2011-08-25 22:08:55 +00:00
|
|
|
import org.parboiled.Parboiled
|
|
|
|
import org.parboiled.parserunners.ReportingParseRunner
|
|
|
|
import org.parboiled.parserunners.RecoveringParseRunner
|
|
|
|
|
2011-09-02 21:47:46 +00:00
|
|
|
makeParser = {
|
|
|
|
println "Making the standard parser."
|
|
|
|
println "---------------------------"
|
2011-08-25 22:08:55 +00:00
|
|
|
|
2011-09-02 21:47:46 +00:00
|
|
|
parser = Parboiled.createParser(JLPPegParser.class)
|
|
|
|
parseRunner = new ReportingParseRunner(parser.SourceFile())
|
|
|
|
}
|
|
|
|
|
|
|
|
makeExperimentalParser = {
|
|
|
|
println "Making the experimental parser."
|
|
|
|
println "-------------------------------"
|
|
|
|
|
|
|
|
parser = Parboiled.createParser(com.jdblabs.jlp.experimental.JLPPegParser.class)
|
|
|
|
parseRunner = new ReportingParseRunner(parser.SourceFile())
|
|
|
|
}
|
2011-08-29 14:44:05 +00:00
|
|
|
|
|
|
|
simpleTest = {
|
2011-09-02 21:47:46 +00:00
|
|
|
println "Parsing the simple test into 'result'."
|
|
|
|
println "--------------------------------------"
|
2011-08-29 14:44:05 +00:00
|
|
|
|
|
|
|
testLine = """%% This the first test line.
|
|
|
|
%% Second Line
|
2011-09-02 21:47:46 +00:00
|
|
|
%% Third Line \n\n Fifth line \n\n %% Seventh line \n\n
|
|
|
|
%% @author Eigth Line
|
|
|
|
%% @Example Ninth Line
|
|
|
|
%% Markdown lines (tenth line)
|
|
|
|
%% Still markdown (eleventh line)
|
|
|
|
Twelfth line is a code line"""
|
|
|
|
|
|
|
|
simpleResult = parseRunner.run(testLine)
|
2011-08-29 14:44:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
vbsTest = {
|
2011-08-31 14:46:25 +00:00
|
|
|
println "Parsing vbs_db_records.hrl into 'vbsResult'."
|
|
|
|
println "--------------------------------------------"
|
2011-08-29 14:44:05 +00:00
|
|
|
|
|
|
|
vbsTestFile = new File('vbs_db_records.hrl')
|
|
|
|
println "vbsTestFile is ${vbsTestFile.exists() ? 'present' : 'absent'}."
|
|
|
|
vbsTestInput = vbsTestFile.text
|
|
|
|
|
2011-08-31 14:46:25 +00:00
|
|
|
vbsParsed = parseRunner.run(vbsTestInput)
|
|
|
|
|
|
|
|
vbsResult = MarkdownGenerator.generateDocuments([vbs: vbsParsed.resultValue]).vbs
|
|
|
|
|
|
|
|
println "Writing to file 'vbs_result.html'."
|
|
|
|
println "----------------------------------"
|
|
|
|
|
|
|
|
(new File('vbs_result.html')).withWriter { out -> out.println vbsResult }
|
2011-08-31 17:09:25 +00:00
|
|
|
|
|
|
|
return [vbsParsed, vbsResult]
|
2011-08-29 14:44:05 +00:00
|
|
|
}
|
2011-09-06 21:13:21 +00:00
|
|
|
|
|
|
|
experimentalTest = {
|
|
|
|
makeExperimentalParser()
|
|
|
|
|
|
|
|
println "Parsing vbs_db_records.hrl into 'vbsResult'."
|
|
|
|
println "--------------------------------------------"
|
|
|
|
|
|
|
|
vbsTestFile = new File('vbs_db_records.hrl')
|
|
|
|
println "vbsTestFile is ${vbsTestFile.exists() ? 'present' : 'absent'}."
|
|
|
|
vbsTestInput = vbsTestFile.text
|
|
|
|
|
|
|
|
vbsParsed = parseRunner.run(vbsTestInput)
|
|
|
|
|
|
|
|
vbsResult = LiterateMarkdownGenerator.generateDocuments(["vbs_db_records.hrl": vbsParsed.resultValue])."vbs_db_records.hrl"
|
|
|
|
|
|
|
|
println "Writing to file 'vbs_result.html'."
|
|
|
|
println "----------------------------------"
|
|
|
|
|
|
|
|
(new File('vbs_result.html')).withWriter { out -> out.println vbsResult }
|
|
|
|
|
|
|
|
}
|