diff --git a/src/Raku/ast/doc-declarator.rakumod b/src/Raku/ast/doc-declarator.rakumod index 2aff0d71782..9b0148abc8f 100644 --- a/src/Raku/ast/doc-declarator.rakumod +++ b/src/Raku/ast/doc-declarator.rakumod @@ -7,6 +7,7 @@ class RakuAST::Doc::Declarator has List $.leading; has List $.trailing; has int $!pod-index; + has List $!paragraphs; method new(:$WHEREFORE, :$leading, :$trailing) { my $obj := nqp::create(self); diff --git a/src/core.c/RakuAST/Fixups.pm6 b/src/core.c/RakuAST/Fixups.pm6 index d677c11a81c..a24aef3c7a8 100644 --- a/src/core.c/RakuAST/Fixups.pm6 +++ b/src/core.c/RakuAST/Fixups.pm6 @@ -1260,4 +1260,21 @@ augment class RakuAST::Type::Enum { } } +augment class RakuAST::Doc::Declarator { + + # Return a 2-element list with all of the leading doc joined and + # parsed as the first elements, and the trailing doc joined and + # parsed as the second element + method paragraphs() { + $!paragraphs + // nqp::bindattr(self,RakuAST::Doc::Declarator,'$!paragraphs', + (self.leading, self.trailing).map({ + $_ + ?? RakuAST::Doc::Paragraph.from-string(.join("\n")) + !! '' + }).List + ) + } +} + # vim: expandtab shiftwidth=4 diff --git a/t/12-rakuast/doc-declarator.rakutest b/t/12-rakuast/doc-declarator.rakutest index 002dda120c8..e979bf3ff74 100644 --- a/t/12-rakuast/doc-declarator.rakutest +++ b/t/12-rakuast/doc-declarator.rakutest @@ -823,18 +823,47 @@ subtest 'a simple lexical var' => { sigil => '$', desigilname => RakuAST::Name.from-identifier('foo'), ).declarator-docs( - leading => ("leading comment\n",), - trailing => ("trailing comment\n",) + leading => ("leading B\n",), + trailing => ("trailing C\n",) ); is-deeply $deparsed, q:to/CODE/.chomp, 'deparse'; -#| leading comment -my $foo #= trailing comment +#| leading B +my $foo #= trailing C , $=pod CODE # since the $=pod semantics are unsure, we're not going # to test that here and now + + is-deeply + $ast.first(RakuAST::Doc::DeclaratorTarget).WHY.paragraphs, + (RakuAST::Doc::Paragraph.new( + "leading ", + RakuAST::Doc::Markup.new( + letter => "B", + opener => "<", + closer => ">", + atoms => ( + "comment", + ) + ), + "\n" + ), + RakuAST::Doc::Paragraph.new( + "trailing ", + RakuAST::Doc::Markup.new( + letter => "C", + opener => "<", + closer => ">", + atoms => ( + "comment", + ) + ), + "\n" + ) + ), + 'did we find the paragraphs ok'; } # vim: expandtab shiftwidth=4