Skip to content

Commit

Permalink
RakuAST: add special handling for =begin comment
Browse files Browse the repository at this point in the history
Specifically with regards to invalid pod before the =end comment
  • Loading branch information
lizmat committed May 3, 2023
1 parent ae1856d commit 6f3c535
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
18 changes: 18 additions & 0 deletions src/Raku/Actions.nqp
Expand Up @@ -2787,6 +2787,24 @@ class Raku::Actions is HLL::Actions does Raku::CommonActions {
$*CU.replace-finish-content(~$<finish>);
}

method doc-block:sym<comment>($/) {
if $*FROM-SEEN{$/.from}++ {
return;
}

my $config := extract-config($/);

my @paragraphs;
if $<lines> -> $lines {
if ~$lines -> $text {
nqp::push(@paragraphs,$text);
}
}

$*SEEN{$/.from} := RakuAST::Doc::Block.from-paragraphs:
:type<comment>, :$config, :@paragraphs;
}

method doc-block:sym<begin>($/) {
if $*FROM-SEEN{$/.from}++ {
return;
Expand Down
20 changes: 19 additions & 1 deletion src/Raku/Grammar.nqp
Expand Up @@ -3569,6 +3569,7 @@ if $*COMPILING_CORE_SETTING {
proto token doc-block {*}
# handle =finish and friends
token doc-block:sym<finish> {
^^ \h*
[
Expand All @@ -3579,6 +3580,23 @@ if $*COMPILING_CORE_SETTING {
$<finish> = .*
}
# handle =begin comment
token doc-block:sym<comment> {
# save any leading whitespace from start of line
^^ $<spaces>=[ \h* ]
# start of 'begin comment' block
'=begin' \h+ 'comment' <doc-configuration($<spaces>)>* <doc-newline>+
# fetch all non-empty lines, *NOT* looking at =pod markers
$<lines>=[^^ \h* \N+ \n?]*?
# until the matching end block
^^ $<spaces> '=end' \h+ 'comment' [<doc-newline> | $]
}
# handle all the other =begin
token doc-block:sym<begin> {
# save any leading whitespace from start of line
Expand All @@ -3605,7 +3623,7 @@ if $*COMPILING_CORE_SETTING {
# should now be at end of line
<.doc-newline>+
# get any content
# get any doc blocks
<doc-content>*
# until the end marker
Expand Down

0 comments on commit 6f3c535

Please sign in to comment.