Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Move Pod-related methods from Actions.pm to Pod.pm
  • Loading branch information
Tadeusz Sośnierz committed Aug 15, 2011
1 parent 7810da2 commit 8da71aa
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 48 deletions.
51 changes: 3 additions & 48 deletions src/Perl6/Actions.pm
Expand Up @@ -323,28 +323,13 @@ class Perl6::Actions is HLL::Actions {
}

method pod_textcontent:sym<regular>($/) {
my @t := self.merge_twines($<pod_string>);
my @t := Perl6::Pod::merge_twines($<pod_string>);
my $twine := Perl6::Pod::serialize_array(@t)<compile_time_value>;
make Perl6::Pod::serialize_object(
'Pod::Block::Para', :content($twine)
)<compile_time_value>
}

method merge_twines(@twines) {
my @ret := @twines.shift.ast;
for @twines {
my @cur := $_.ast;
@ret.push(
$*ST.add_constant(
'Str', 'str',
nqp::unbox_s(@ret.pop) ~ ' ' ~ nqp::unbox_s(@cur.shift)
)<compile_time_value>,
);
nqp::splice(@ret, @cur, +@ret, 0);
}
return @ret;
}

method pod_textcontent:sym<code>($/) {
my $s := $<spaces>.Str;
my $t := subst($<text>.Str, /\n$s/, "\n", :global);
Expand All @@ -361,7 +346,7 @@ class Perl6::Actions is HLL::Actions {
for $<pod_string_character> {
@content.push($_.ast)
}
my @t := self.build_pod_string(@content);
my @t := Perl6::Pod::build_pod_string(@content);
my $past := Perl6::Pod::serialize_object(
'Pod::FormattingCode',
:type(
Expand All @@ -377,37 +362,7 @@ class Perl6::Actions is HLL::Actions {
for $<pod_string_character> {
@content.push($_.ast)
}
make self.build_pod_string(@content);
}

method build_pod_string(@content) {
sub push_strings(@strings, @where) {
my $s := subst(pir::join('', @strings), /\s+/, ' ', :global);
my $t := $*ST.add_constant(
'Str', 'str', $s
)<compile_time_value>;
@where.push($t);
}

my @res := [];
my @strs := [];
for @content -> $elem {
if pir::typeof($elem) eq 'String' {
# don't push the leading whitespace
if +@res + @strs == 0 && $elem eq ' ' {

} else {
@strs.push($elem);
}
} else {
push_strings(@strs, @res);
@strs := [];
@res.push($elem);
}
}
push_strings(@strs, @res);

return @res;
make Perl6::Pod::build_pod_string(@content);
}

method pod_string_character($/) {
Expand Down
46 changes: 46 additions & 0 deletions src/Perl6/Pod.pm
Expand Up @@ -247,6 +247,52 @@ class Perl6::Pod {
return @result;
}

our sub merge_twines(@twines) {
my @ret := @twines.shift.ast;
for @twines {
my @cur := $_.ast;
@ret.push(
$*ST.add_constant(
'Str', 'str',
nqp::unbox_s(@ret.pop) ~ ' ' ~ nqp::unbox_s(@cur.shift)
)<compile_time_value>,
);
nqp::splice(@ret, @cur, +@ret, 0);
}
return @ret;
}

our sub build_pod_string(@content) {
sub push_strings(@strings, @where) {
my $s := subst(pir::join('', @strings), /\s+/, ' ', :global);
my $t := $*ST.add_constant(
'Str', 'str', $s
)<compile_time_value>;
@where.push($t);
}

my @res := [];
my @strs := [];
for @content -> $elem {
if pir::typeof($elem) eq 'String' {
# don't push the leading whitespace
if +@res + @strs == 0 && $elem eq ' ' {

} else {
@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)
our sub splitrows(@rows) {
Expand Down

0 comments on commit 8da71aa

Please sign in to comment.