From 416658440b11932d405aba0025d669f068629ea9 Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Sat, 23 Jun 2012 10:46:25 +0300 Subject: [PATCH] parse (badly) first example file --- lib/Pod/Parser.pm | 40 +++++++++++++++++++++++++++++++++++++++- t/01-parse.t | 13 ++++++++++++- t/files/a.pod | 17 +++++++++++++++++ 3 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 t/files/a.pod diff --git a/lib/Pod/Parser.pm b/lib/Pod/Parser.pm index e806b48..57065a6 100644 --- a/lib/Pod/Parser.pm +++ b/lib/Pod/Parser.pm @@ -1,7 +1,6 @@ use v6; class Pod::Parser; - =begin pod =head1 NAME @@ -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 diff --git a/t/01-parse.t b/t/01-parse.t index 33f6813..f9b5462 100644 --- a/t/01-parse.t +++ b/t/01-parse.t @@ -1,6 +1,6 @@ use v6; use Test; -plan 2; +plan 3; use Pod::Parser; ok 1, 'Loading module succeeded'; @@ -8,4 +8,15 @@ 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; diff --git a/t/files/a.pod b/t/files/a.pod new file mode 100644 index 0000000..eea53d9 --- /dev/null +++ b/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 +