Skip to content

Commit

Permalink
parse (badly) first example file
Browse files Browse the repository at this point in the history
  • Loading branch information
szabgab committed Jun 23, 2012
1 parent 1af73fb commit 4166584
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
40 changes: 39 additions & 1 deletion lib/Pod/Parser.pm
@@ -1,7 +1,6 @@
use v6;
class Pod::Parser;


=begin pod
=head1 NAME
Expand All @@ -10,4 +9,43 @@ Pod::Parser - parsing files with POD in them (Perl 6 syntax)
=end pod

my $in_pod = 0;
my $pod = '';
my $text = '';

method parse (Str $string) {
my @lines = $string.split("\n");
my @data;
for @lines -> $row {
if $row ~~ m/^\=begin \s+ pod \s* $/ {
$in_pod = 1;
if $text ne '' {
@data.push($text);
$text = '';
}
next;
}
if $row ~~ m/^\=end \s+ pod \s* $/ {
$in_pod = 0;
if $pod ne '' {
@data.push($pod);
$pod = '';
}
next;
}
if $in_pod {
$pod ~= "$row\n";
next;
}
$text ~= "$row\n";
}
return @data;
}

method parse_file (Str $filename) {
my $string = slurp($filename);
self.parse($string);
}


# vim: ft=perl6
13 changes: 12 additions & 1 deletion t/01-parse.t
@@ -1,11 +1,22 @@
use v6;
use Test;
plan 2;
plan 3;

use Pod::Parser;
ok 1, 'Loading module succeeded';

my $pp = Pod::Parser.new;
isa_ok $pp, 'Pod::Parser';

my @result = $pp.parse_file('t/files/a.pod');
is_deeply @result, Array.new(
"text before\n\n",
"\n=head1 NAME\n\nText in name\n\n=head1 SYNOPSIS\n\n some verbatime\n text\n\n"), 'parse a.pod';
#say Pod::Parser::parse($case);

#say %tree;

#is_deeply(


done;
17 changes: 17 additions & 0 deletions t/files/a.pod
@@ -0,0 +1,17 @@
text before

=begin pod
=head1 NAME
Text in name
=head1 SYNOPSIS
some verbatime
text
=end pod

text after

0 comments on commit 4166584

Please sign in to comment.