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("%% " +}