Skip to content

Commit

Permalink
Allow escaping POD column sep. Fixes #1282
Browse files Browse the repository at this point in the history
Add code to fix rakudo issue #1282; allows escaping column separators to use as
cell data; Tests to be added with Raku/roast#361
  • Loading branch information
tbrowder authored and samcv committed Dec 7, 2017
1 parent d80df07 commit 11d90ca
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 5 deletions.
56 changes: 51 additions & 5 deletions src/Perl6/Pod.nqp
Expand Up @@ -327,6 +327,40 @@ class Perl6::Pod {
return $*W.add_constant($type, 'type_new', |@pos, |%named);
}

# TODO This sub is for future work on pod formatting issues.
# It isn't currently used.
sub string2twine($S) {
# takes a simple string with unhandled formatting code
# and converts it into a twine data structure. primarily
# designed for a table cell.
# note all Z<> comments have already been removed.
my $s := $S; # the raw string to be converted to a twine
my $ret := ''; # the cleaned string (i.e., without comments)
my $idx := nqp::index($s, '<'); # find the possible beginning of a formatting code
if $idx < 0 {
# no '<' found so return the simple string
return $s;
}

while $idx > -1 {
my $idx2 := nqp::index($s, '>', $idx+2); # and the end
nqp::die("FATAL: Couldn't find terminator '>' for inline pod format code in string '$s' in Table $table_num") if $idx2 < 0;
my $s0 := nqp::substr($s, 0, $idx); # the leading chunk (which may be empty)
# assemble the cleaned string by parts
$ret := nqp::concat($ret, $s0);

# throw away the orig string up to the end of the found comment
$s := nqp::substr($s, $idx2+1); # the trailing chunk
# look for another comment in the remaining string
$idx := nqp::index($s, 'Z<');
}

# make sure we use up a non-empty string end
$ret := nqp::concat($ret, $s) if $s;

return $ret;
}

our sub table($/) {
my $config := $<pod_configuration>
?? $<pod_configuration>.ast
Expand Down Expand Up @@ -580,7 +614,7 @@ class Perl6::Pod {
$content := @newrows;
}

# show final table matrix (TODO put in a sub?? YES)
# show final table matrix
if $debug || $udebug {
# show final table matrix
show_final_table_matrix($headers, $content);
Expand All @@ -598,6 +632,12 @@ class Perl6::Pod {
return $past.compile_time_value;

#===== TABLE-SPECIFIC SUBROUTINES =====
sub unescape-col-seps($S) {
my $s := subst($S, /'\+'/, '+', :global);
$s := subst($s, /'\|'/, '|', :global);
return $s;
}

sub handle_table_issues(@rows) {
my $t := $table_num;
#=== invalid tables generate exceptions
Expand Down Expand Up @@ -753,13 +793,15 @@ class Perl6::Pod {
elsif nqp::isstr($row) {
# just split the row
nqp::say("VIS BEFORE SPLIT: '$row'") if $debug;
my @t := nqp::split('|', $row);
# TODO split on ' | '
# TODO unescape | and +
my @t := nqp::split(' | ', $row);
my @tmp := [];
my $j := 0;
for @t {
my $c := $_;
nqp::say(" CELL $j: '$c'") if $debug;
$c := normalize_text($c);
$c := normalize_text(unescape-col-seps($c));
nqp::say(" CELL $j normalized: '$c'") if $debug;
@tmp.push($c);
++$j;
Expand Down Expand Up @@ -869,12 +911,14 @@ class Perl6::Pod {
next if $a > nqp::chars($row);
if $b {
@tmp.push(
normalize_text(nqp::substr($row, $a, $b - $a))
# TODO unescape | and +
normalize_text(unescape-col-seps(nqp::substr($row, $a, $b - $a)))
);
}
else {
@tmp.push(
normalize_text(nqp::substr($row, $a))
# TODO unescape | and +
normalize_text(unescape-col-seps(nqp::substr($row, $a)))
);
}
}
Expand Down Expand Up @@ -904,6 +948,8 @@ class Perl6::Pod {
sub normalize_row_cells($row) {
# forces a pipe separator as the row cell separator
my $s := $row;
# add trailing ws to ensure correct split later
$s := nqp::concat($s, ' ');
$s := subst($s, /\h'+'\h/, $col_sep_pipe_literal, :global);
return $s;
}
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data
Expand Up @@ -925,6 +925,7 @@ S26-documentation/06-lists.t
S26-documentation/07-tables.t
S26-documentation/07a-tables.t
S26-documentation/07b-tables.t
S26-documentation/07c-tables.t
S26-documentation/08-formattingcodes.t
S26-documentation/09-configuration.t
S26-documentation/10-doc-cli.t
Expand Down
1 change: 1 addition & 0 deletions t/spectest.data.6.c
Expand Up @@ -842,6 +842,7 @@ S26-documentation/06-lists.t
S26-documentation/07-tables.t
S26-documentation/07a-tables.t
S26-documentation/07b-tables.t
S26-documentation/07c-tables.t
S26-documentation/08-formattingcodes.t
S26-documentation/09-configuration.t
S26-documentation/10-doc-cli.t
Expand Down

0 comments on commit 11d90ca

Please sign in to comment.