From 40b00e8757fdc5b8415a2e1c06601e66307a4247 Mon Sep 17 00:00:00 2001 From: Francois Perrad Date: Thu, 26 Mar 2009 10:15:00 +0100 Subject: [PATCH] whole refactor codeblock --- src/Compiler.pir | 28 ++-------------------------- src/parser/actions.pm | 25 ++++++++++++++++++++++++- src/parser/grammar.pg | 10 ++++++---- 3 files changed, 32 insertions(+), 31 deletions(-) diff --git a/src/Compiler.pir b/src/Compiler.pir index 951f79f..05d45e9 100644 --- a/src/Compiler.pir +++ b/src/Compiler.pir @@ -49,7 +49,6 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes. .sub 'escape_code' :anon .param string str - str = escape_xml(str) $P0 = split '>', str str = join '>', $P0 .return (str) @@ -77,29 +76,6 @@ Markdown::HTML::Compiler implements a compiler for MAST nodes. .return ($S0) .end -.sub 'detab' :anon - .param string str - $P0 = split "\n", str - $P1 = new 'ResizableStringArray' - L1: - unless $P0 goto L2 - $S0 = shift $P0 - $S1 = substr $S0, 0, 1 - unless $S1 == "\t" goto L3 - $S0 = substr $S0, 1 - goto L4 - L3: - $S1 = substr $S0, 0, 4 - unless $S1 == ' ' goto L4 - $S0 = substr $S0, 4 - L4: - push $P1, $S0 - goto L1 - L2: - str = join "\n", $P1 - .return (str) -.end - =item html_children(node) @@ -201,8 +177,7 @@ Return generated HTML for all of its children. .sub 'html' :method :multi(_,['Markdown';'CodeBlock']) .param pmc node - $S1 = node.'text'() - $S1 = detab($S1) + $S1 = self.'html_children'(node) $S1 = escape_code($S1) .local pmc code new code, 'CodeString' @@ -458,6 +433,7 @@ Return generated HTML for all of its children. .sub 'html' :method :multi(_,['Markdown';'Code']) .param pmc node $S1 = node.'text'() + $S1 = escape_xml($S1) $S1 = escape_code($S1) .local pmc code new code, 'CodeString' diff --git a/src/parser/actions.pm b/src/parser/actions.pm index c21a3e3..38253fb 100644 --- a/src/parser/actions.pm +++ b/src/parser/actions.pm @@ -103,8 +103,31 @@ method RawLine($/) { make Markdown::Line.new( :text( $/[0] ) ); } +method BlankLine($/) { + make Markdown::Line.new( :text( $/.text() ) ); +} + +method NonblankIndentedLine($/) { + make Markdown::Line.new( :text( ~$.text() ) ); +} + +method VerbatimChunk($/) { + my $mast := Markdown::Node.new(); + for $ { + $mast.push( $( $_ ) ); + } + for $ { + $mast.push( $( $_ ) ); + } + make $mast; +} + method Verbatim($/) { - make Markdown::CodeBlock.new( :text( $/.text() ) ); + my $mast := Markdown::CodeBlock.new(); + for $ { + $mast.push( $( $_ ) ); + } + make $mast; } method HorizontalRule($/) { diff --git a/src/parser/grammar.pg b/src/parser/grammar.pg index 39df6d3..eb4a2c6 100644 --- a/src/parser/grammar.pg +++ b/src/parser/grammar.pg @@ -86,15 +86,17 @@ token BlockQuoteRaw { token _Chevron { '>' } token NonblankIndentedLine { - <.IndentedLine> + + {*} } token VerbatimChunk { - <.BlankLine>* <.NonblankIndentedLine>+ + * + + {*} } token Verbatim { - <.VerbatimChunk>+ + + {*} } @@ -481,7 +483,7 @@ token _Code5 { ]+ } -token BlankLine { <.Sp> <.Newline> } +token BlankLine { <.Sp> <.Newline> {*} } token Eof { $ }