Skip to content
This repository has been archived by the owner on Jun 9, 2018. It is now read-only.

Commit

Permalink
whole refactor codeblock
Browse files Browse the repository at this point in the history
  • Loading branch information
fperrad committed Mar 26, 2009
1 parent 0ff6b01 commit 40b00e8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 31 deletions.
28 changes: 2 additions & 26 deletions src/Compiler.pir
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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'
Expand Down
25 changes: 24 additions & 1 deletion src/parser/actions.pm
Expand Up @@ -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( ~$<IndentedLine><Line><RawLine>.text() ) );
}

method VerbatimChunk($/) {
my $mast := Markdown::Node.new();
for $<BlankLine> {
$mast.push( $( $_ ) );
}
for $<NonblankIndentedLine> {
$mast.push( $( $_ ) );
}
make $mast;
}

method Verbatim($/) {
make Markdown::CodeBlock.new( :text( $/.text() ) );
my $mast := Markdown::CodeBlock.new();
for $<VerbatimChunk> {
$mast.push( $( $_ ) );
}
make $mast;
}

method HorizontalRule($/) {
Expand Down
10 changes: 6 additions & 4 deletions src/parser/grammar.pg
Expand Up @@ -86,15 +86,17 @@ token BlockQuoteRaw {
token _Chevron { '>' }

token NonblankIndentedLine {
<!BlankLine> <.IndentedLine>
<!BlankLine> <IndentedLine>
{*}
}

token VerbatimChunk {
<.BlankLine>* <.NonblankIndentedLine>+
<BlankLine>* <NonblankIndentedLine>+
{*}
}

token Verbatim {
<.VerbatimChunk>+
<VerbatimChunk>+
{*}
}

Expand Down Expand Up @@ -481,7 +483,7 @@ token _Code5 {
]+
}

token BlankLine { <.Sp> <.Newline> }
token BlankLine { <.Sp> <.Newline> {*} }

token Eof { $ }

Expand Down

0 comments on commit 40b00e8

Please sign in to comment.