Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Save text verbatim when in a code block
  • Loading branch information
Mouq committed Feb 19, 2014
1 parent 5accaed commit e2b8379
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/Perl6/Grammar.nqp
Expand Up @@ -544,7 +544,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
# text not being code
token pod_textcontent:sym<regular> {
$<spaces>=[ \h* ]
<?{ !$*ALLOW_INLINE_CODE
<?{ $*POD_IN_CODE_BLOCK
|| !$*ALLOW_INLINE_CODE
|| ($<spaces>.to - $<spaces>.from) <= $*VMARGIN }>

$<text> = [
Expand All @@ -554,7 +555,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {

token pod_textcontent:sym<code> {
$<spaces>=[ \h* ]
<?{ $*ALLOW_INLINE_CODE
<?{ !$*POD_IN_CODE_BLOCK
&& $*ALLOW_INLINE_CODE
&& ($<spaces>.to - $<spaces>.from) > $*VMARGIN }>
$<text> = [
[<!before '=' \w> \N+]+ % [<pod_newline> $<spaces>]
Expand Down Expand Up @@ -688,8 +690,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
^^
$<spaces> = [ \h* ]
'=begin' \h+ 'code'
:my $*POD_ALLOW_FCODES := 0;
:my $*ALLOW_INLINE_CODE := 0;
:my $*POD_ALLOW_FCODES := 0;
:my $*POD_IN_CODE_BLOCK := 1;
<pod_configuration($<spaces>)> <pod_newline>+
[
|| <delimited_code_content(~$<spaces>)>
Expand Down Expand Up @@ -794,8 +796,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
^^
$<spaces> = [ \h* ]
'=code' <pod_configuration($<spaces>)> <pod_newline>
:my $*POD_ALLOW_FCODES := 0;
:my $*ALLOW_INLINE_CODE := 0;
:my $*POD_ALLOW_FCODES := 0;
:my $*POD_IN_CODE_BLOCK := 1;
[ <pod_string> <pod_newline> ]+
}

Expand Down Expand Up @@ -861,7 +863,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
:my $*HAS_YOU_ARE_HERE := 0; # whether {YOU_ARE_HERE} has shown up
:my $*OFTYPE;
:my $*VMARGIN := 0; # pod stuff
:my $*ALLOW_INLINE_CODE := 0; # pod stuff
:my $*ALLOW_INLINE_CODE := 0; # pod stuff
:my $*POD_IN_CODE_BLOCK := 0; # pod stuff
:my $*POD_IN_FORMATTINGCODE := 0; # pod stuff
:my $*POD_ALLOW_FCODES := 0b11111111111111111111111111; # allow which fcodes?
:my $*POD_ANGLE_COUNT := 0; # pod stuff
Expand Down
31 changes: 31 additions & 0 deletions src/Perl6/Pod.nqp
Expand Up @@ -335,6 +335,12 @@ class Perl6::Pod {
}

our sub build_pod_string(@content) {
return $*POD_IN_CODE_BLOCK
?? build_pod_code_string(@content)
!! build_pod_regular_string(@content)
}

our sub build_pod_regular_string(@content) {
sub push_strings(@strings, @where) {
my $s := subst(nqp::join('', @strings), /\s+/, ' ', :global);
my $t := $*W.add_constant(
Expand Down Expand Up @@ -364,6 +370,31 @@ class Perl6::Pod {
return @res;
}

# Code strings need to be handled differently:
# Formatting codes need to be saved, but everything
# else should be verbatim
our sub build_pod_code_string(@content) {
sub push_strings(@strings, @where) {
my $s := nqp::join('', @strings);
my $t := $*W.add_constant('Str', 'str', $s).compile_time_value;
@where.push($t);
}

my @res := [];
my @strs := [];
for @content -> $elem {
if nqp::isstr($elem) {
@strs.push($elem);
} else {
push_strings(@strs, @res);
@strs := [];
@res.push($elem);
}
}
push_strings(@strs, @res);

return @res;
}

# takes an array of strings (rows of a table)
# returns array of arrays of strings (cells)
Expand Down

0 comments on commit e2b8379

Please sign in to comment.