Skip to content

Commit

Permalink
RakuAST: fix issues with $=pod generation and markup
Browse files Browse the repository at this point in the history
This moves the :allow functionality to the legacy podification as
"renderer".  Fixes many of the tests in the "doc" repository.
  • Loading branch information
lizmat committed Jul 23, 2023
1 parent b58bf6d commit 947b49c
Showing 1 changed file with 47 additions and 30 deletions.
77 changes: 47 additions & 30 deletions src/core.c/RakuAST/LegacyPodify.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -157,15 +157,17 @@ class RakuAST::LegacyPodify {

multi method podify(RakuAST::Doc::Markup:D $ast) {
my str $letter = $ast.letter;
$letter eq 'V'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! Pod::FormattingCode.new(
type => $letter,
meta => $ast.meta,
contents => $letter eq 'C'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! self!contentify-atoms($ast)
)
%*OK{$letter}
?? $letter eq 'V'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! Pod::FormattingCode.new(
type => $letter,
meta => $ast.meta,
contents => $letter eq 'C'
?? $ast.atoms.head.subst("\n", ' ', :g)
!! self!contentify-atoms($ast)
)
!! $ast.Str
}

multi method podify(RakuAST::Doc::Paragraph:D $ast) {
Expand Down Expand Up @@ -197,23 +199,42 @@ class RakuAST::LegacyPodify {
}

multi method podify(RakuAST::Doc::Block:D $ast) {
my str $type = $ast.type;
my str $level = $ast.level;
my str $type = $ast.type;
my $config := $ast.resolved-config;

# Set up dynamic lookup for allowable markup letters
my %*OK := do {
# default for allowable markup letters
my constant %OK = ("A".."Z").map: { $_ => True }
my constant %NOK = ();

# a specific set
if $config && $config<allow> -> $allow {
Map.new( @$allow.map( { $_ => True } ) )
}

# these need code of its own, as the new grammar only collects
# all or nothing
else {
$type eq <code defn implicit-code input output table>.any
?? %NOK
!! %OK
}
}

# These need code of its own, as the new grammar only collects
# and does not do any interpretation
my str $level = $ast.level;
unless $level {
return self.podify-table($ast)
return self.podify-table($ast, $config)
if $type eq 'table';
return self.podify-code($ast, $type)
return self.podify-verbatim($ast, $type, $config)
if $type eq 'code' | 'input' | 'output';
return self.podify-implicit-code($ast)
return self.podify-implicit-code($ast, $config)
if $type eq 'implicit-code';
return self.podify-defn($ast)
if $type eq 'defn';
}

my $config := $ast.resolved-config;
my $contents := no-last-nl($ast.paragraphs).map({
if nqp::istype($_,Str) {
if sanitize(.trim-leading) -> $contents {
Expand Down Expand Up @@ -249,9 +270,8 @@ class RakuAST::LegacyPodify {
!! $contents # no type means just a string
}

method podify-table(RakuAST::Doc::Block:D $ast) {
my @rows = $ast.paragraphs.grep(RakuAST::Doc::Row);
my $config := $ast.resolved-config // Map.new;
method podify-table(RakuAST::Doc::Block:D $ast, $config) {
my @rows = $ast.paragraphs.grep(RakuAST::Doc::Row);

# Make sure that all rows have the same number of cells
my $nr-columns := @rows.map(*.cells.elems).max;
Expand Down Expand Up @@ -300,15 +320,17 @@ class RakuAST::LegacyPodify {
)
}

method podify-code(RakuAST::Doc::Block:D $ast, Str:D $type) {
method podify-verbatim(RakuAST::Doc::Block:D $ast, Str:D $type, $config) {
my @contents = $ast.paragraphs.map({
(nqp::istype($_,Str)
?? .split("\n", :v, :skip-empty)
# assume a paragraph with string / markup atoms
!! .atoms.map({
nqp::istype($_,Str)
?? .split("\n", :v, :skip-empty).Slip
!! .podify
!! nqp::istype($_,RakuAST::Doc::Markup) && %*OK{.letter}
?? .podify
!! .Str
})
).Slip
});
Expand All @@ -317,17 +339,12 @@ class RakuAST::LegacyPodify {
@contents.pop while @contents.tail eq "\n";
@contents.push("\n");

::("Pod::Block::$type.tc()").new:
:@contents, :config($ast.resolved-config)
::("Pod::Block::$type.tc()").new: :@contents, :$config
}

method podify-implicit-code(RakuAST::Doc::Block:D $ast) {
my $contents := $ast.paragraphs.head;
$contents := nqp::istype($contents,Str)
?? $contents.trim
!! $contents.podify;

Pod::Block::Code.new: :$contents, :config($ast.resolved-config)
method podify-implicit-code(RakuAST::Doc::Block:D $ast, $config) {
Pod::Block::Code.new:
:contents($ast.paragraphs.head.Str.trim), :$config
}

method podify-defn(RakuAST::Doc::Block:D $ast) {
Expand Down

0 comments on commit 947b49c

Please sign in to comment.