From 303f8839fd9d67899318e55e72ec5d2143f41c3d Mon Sep 17 00:00:00 2001 From: Jonathan Bernard Date: Thu, 25 Aug 2011 07:47:01 -0500 Subject: [PATCH] More work on grammar, starting parboiled implementation. --- doc/grammar.rst | 18 ++++++++++++------ src/com/jdblabs/jlp/JLPPegParser.groovy | 19 +++++++++++++++++++ 2 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 src/com/jdblabs/jlp/JLPPegParser.groovy diff --git a/doc/grammar.rst b/doc/grammar.rst index bbf532e..1e99e0d 100644 --- a/doc/grammar.rst +++ b/doc/grammar.rst @@ -1,7 +1,7 @@ -CodePage -> CodeBlock | DocBlock | CodePage +CodePage -> (CodeBlock | DocBlock)* // lookahead 2 needed here -DocBlock -> DirectiveBlock | MarkdownBlock | DocBlock +DocBlock -> (DirectiveBlock | MarkdownBlock)+ DirectiveBlock -> "author" RemainingLine EOL MarkdownBlock? | @@ -15,11 +15,17 @@ MarkdownLine -> NOT_DIRECTIVE_START RemainingLine RemainingLine -> NOT_EOL* + +OrgString -> + ( )* ? + Tokens ------ -DOC_START -> "%%" -EOL -> "\n" -NOT_EOL -> ~"\n" -DIRECTIVE_START -> "@" +DOC_START -> "%% " +EOL -> "\n" +NOT_EOL -> ~"\n" +DIRECTIVE_START -> "@" NOT_DIRECTIVE_START -> ~"@" +SLASH -> "/" +ORG_ID -> ~"[/\n]" diff --git a/src/com/jdblabs/jlp/JLPPegParser.groovy b/src/com/jdblabs/jlp/JLPPegParser.groovy new file mode 100644 index 0000000..1169f19 --- /dev/null +++ b/src/com/jdblabs/jlp/JLPPegParser.groovy @@ -0,0 +1,19 @@ +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("%% " +}