Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Parse lists properly, makes 06-lists.t
  • Loading branch information
Tadeusz Sośnierz committed Jul 7, 2011
1 parent 48ed49c commit 3a828b7
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 9 deletions.
19 changes: 18 additions & 1 deletion src/Perl6/Actions.pm
Expand Up @@ -261,7 +261,6 @@ class Perl6::Actions is HLL::Actions {
}

method any_block($/) {
my $name := $*ST.add_constant('Str', 'str', $<type>.Str);
my @children := [];
for $<pod_content> {
# not trivial, for it can be either an array or a pod node
Expand All @@ -280,6 +279,24 @@ class Perl6::Actions is HLL::Actions {
'Array', 'type_new',
|@children,
);
if $<type>.Str ~~ /^item \d*$/ {
my $level := nqp::substr($<type>.Str, 4);
my $level_past;
if $level ne '' {
$level_past := $*ST.add_constant(
'Int', 'int', +$level,
)<compile_time_value>;
} else {
$level_past := $*ST.find_symbol(['Mu']);
}
my $past := $*ST.add_constant(
'Pod__Item', 'type_new',
:level($level_past),
:content($content<compile_time_value>),
);
return $past<compile_time_value>;
}
my $name := $*ST.add_constant('Str', 'str', $<type>.Str);
my $past := $*ST.add_constant(
'Pod__Block__Named', 'type_new',
:name($name<compile_time_value>),
Expand Down
10 changes: 2 additions & 8 deletions src/Perl6/Grammar.pm
Expand Up @@ -239,10 +239,7 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*VMARGIN := $<spaces>.to - $<spaces>.from;
:my $*ALLOW_CODE := 0;
'=for' \h+ <!before 'END'>
$<type> = [
<pod_code_parent> { $*ALLOW_CODE := 1 }
|| <identifier>
]
$<type> = <identifier>

<pod_newline>
$<pod_content> = <pod_textcontent>?
Expand All @@ -262,10 +259,7 @@ grammar Perl6::Grammar is HLL::Grammar {
:my $*VMARGIN := $<spaces>.to - $<spaces>.from;
:my $*ALLOW_CODE := 0;
'=' <!before begin || end || for || END>
$<type> = [
<pod_code_parent> { $*ALLOW_CODE := 1 }
|| <identifier>
]
$<type> = <identifier>
\s
$<pod_content> = <pod_textcontent>?
}
Expand Down
4 changes: 4 additions & 0 deletions src/core/Pod.pm
Expand Up @@ -12,4 +12,8 @@ class Pod__Block__Code is Pod__Block {
has @.allowed;
}

class Pod__Item is Pod__Block {
has $.level;
}

# vim: ft=perl6
105 changes: 105 additions & 0 deletions t/pod/06-lists.t
@@ -0,0 +1,105 @@
use Test;
plan 31;
my $r;

=begin pod
The seven suspects are:
=item Happy
=item Dopey
=item Sleepy
=item Bashful
=item Sneezy
=item Grumpy
=item Keyser Soze
=end pod

$r = $POD[0];
is $r.content.elems, 8;
for 1..7 {
isa_ok $r.content[$_], Pod__Item;
}

is $r.content[1].content, 'Happy', 'content is happy :)';
is $r.content[2].content, 'Dopey';
is $r.content[7].content, 'Keyser Soze';
nok $r.content[4].level.defined, 'no level information';

=begin pod
=item1 Animal
=item2 Vertebrate
=item2 Invertebrate
=item1 Phase
=item2 Solid
=item2 Liquid
=item2 Gas
=item2 Chocolate
=end pod

$r = $POD[1];
is $r.content.elems, 8;
for 0..7 {
isa_ok $r.content[$_], Pod__Item;
}

$r.content[0].content, 'Animal';
$r.content[0].level, 1;
$r.content[2].content, 'Invertebrate';
$r.content[2].level, 2;
$r.content[3].content, 'Phase';
$r.content[3].level, 1;
$r.content[4].content, 'Solid';
$r.content[4].level, 2;

=begin pod
=comment CORRECT...
=begin item1
The choices are:
=end item1
=item2 Liberty
=item2 Death
=item2 Beer
=end pod

$r = $POD[2];
is $r.content.elems, 5;
for 1..4 {
isa_ok $r.content[$_], Pod__Item;
}

# XXX Those items are :numbered in S26, but we're waiting with block
# configuration until we're inside Rakudo, otherwise we'll have to
# pretty much implement Pair parsing in gsocmess only to get rid of
# it later.

=begin pod
Let's consider two common proverbs:
=begin item
I<The rain in Spain falls mainly on the plain.>
This is a common myth and an unconscionable slur on the Spanish
people, the majority of whom are extremely attractive.
=end item
=begin item
I<The early bird gets the worm.>
In deciding whether to become an early riser, it is worth
considering whether you would actually enjoy annelids
for breakfast.
=end item
As you can see, folk wisdom is often of dubious value.
=end pod

$r = $POD[3];
is $r.content.elems, 4;
is $r.content[0], "Let's consider two common proverbs:";
skip 'no regexes in nom yet', 2;
#ok $r.content[1].content.Str
# ~~ /:s This is a common .+ are extremely attractive/;
#ok $r.content[2].content.Str
# ~~ /:s In deciding .+ annelids for breakfast/;
is $r.content[3], "As you can see, folk wisdom is often of dubious value.";

0 comments on commit 3a828b7

Please sign in to comment.