Permalink
Browse files

rename Test emitter to Diag and refactor many action methods

  • Loading branch information...
1 parent fc49d7a commit b8a625a3c1201f0a103441fbc1165a9c54f07c68 Martin Berends committed Apr 10, 2009
View
@@ -5,7 +5,7 @@
# git clone git://github.com/mberends/podtreeparser.git
# cd podtreeparser && perl6 Configure.p6 && make test
-# Chat with the author and P6 developers in #perl6 on irc.freenode.net.
+# Chat with the author and P6 developers in #perl6 at irc.freenode.net.
# Bugs:
# These Pod tools may give errors running with certain revisions of
@@ -15,21 +15,19 @@
# Configure.p6 replaces <TOKENS> when converting Makefile.in -> Makefile
PERL6 = <PERL6>
RAKUDO_DIR = <RAKUDO_DIR>
-# The variables PERL6LIB and PERL6BIN are not required in this Makefile.
+# Variables PERL6LIB and PERL6BIN not used in this Makefile.
-all: precompile
-
-precompile: lib/Pod/Tree/Parser.pir lib/Pod/Tree/Test.pir \
- lib/Pod/Tree/Text.pir lib/Pod/Tree/Man.pir lib/Pod/Tree/Xhtml.pir \
- lib/Pod/Tree/Pod5.pir lib/Pod/Tree/Pod6.pir \
- lib/Test.pir lib/Test/Harness.pir lib/Test/Differences.pir
-
-# define how to precompile a module from its source code
+# make-fu from http://www.gnu.org/software/make/manual/make.html
+SOURCES=$(wildcard lib/Pod/Tree/*.pm) $(wildcard lib/Test/*.pm)
+PIRS=lib/Test.pir $(SOURCES:.pm=.pir)
+# define how to precompile a module from its source
.SUFFIXES: .pm .pir
.pm.pir: $(PERL6) Makefile
@echo 'precompile $< -> $@'
@export PERL6LIB=./lib; $(PERL6) --target=pir --output=$@ $<
+all: $(PIRS)
+
# avoid duplication - precompile the Test module from the Parrot source
lib/Test.pir: $(RAKUDO_DIR)/Test.pm $(PERL6) Makefile
@echo 'precompile $(RAKUDO_DIR)/Test.pm -> lib/Test.pir'
@@ -18,27 +18,26 @@ class Pod::Tree::Test does Pod::Tree::Parser {
elsif defined($/<pod5>) { make ~ $/<pod5>.ast; }
}
method ambient($/) {
-# my Str $ambient = ~ $0;
-# chomp $ambient;
-# make "ambient $ambient\n";
make [~] map( { "ambient $_\n" }, $/.comb(/\N+/) );
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make [~]map({$_.ast},@($/<p6delim>));}
+ elsif defined($/<p6para>) { make [~]map({$_.ast},@($/<p6para>));}
+ elsif defined($/<p6abbr>) { make [~]map({$_.ast},@($/<p6abbr>));}
}
method p6delim($/) {
- my Str $p6 = ~ $/<content>.ast;
- make "blk beg pod DELIMITED version=>6\n$p6"
- ~ "blk end pod DELIMITED\n";
+ my Str $typename = ~ $0<typename>;
+ my Str $delimited;
+ if defined($/<content>) { $delimited = ~ $/<content>.ast; }
+ elsif defined($/<pod6>) { $delimited = ~ $/<pod6>.ast; }
+ make "blk beg $typename DELIMITED version=>6\n$delimited"
+ ~ "blk end $typename DELIMITED\n";
}
method p6para($/) {
-# warn "P6PARA in";
+ my Str $typename = ~ $/<typename>;
my Str $p6para = ~ $/<content>.ast;
- make "blk beg pod PARAGRAPH version=>6\n$p6para"
- ~ "blk end pod PARAGRAPH\n";
-# warn "P6PARA ok";
+ make "blk beg $typename PARAGRAPH version=>6\n$p6para"
+ ~ "blk end $typename PARAGRAPH\n";
}
method pod5($/) {
my Str $p5 = ~ $/<content>.ast;
View
@@ -21,9 +21,9 @@ class Pod::Tree::Man does Pod::Tree::Parser {
make "ambient $ambient\n";
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make ~ $/<p6delim>[0].ast; }
+ elsif defined($/<p6para>) { make ~ $/<p6para>[0].ast; }
+ elsif defined($/<p6abbr>) { make ~ $/<p6abbr>[0].ast; }
}
method p6delim($/) {
my Str $p6 = ~ $/<content>.ast;
View
@@ -3,32 +3,38 @@
# Specification: Perl6/Spec/S26-documentation.pod
# version: 2007-04-25 by Damian Conway
-# :-) Perl 6 connects regular expressions to actions via the grammar
+# Perl 6 connects regular expressions to actions via the grammar
grammar Perldoc {
regex TOP { ^ <section> * $ {*} }
- # Deviate from S26 by matching much of both Perl 5 and Perl 6 Pod
+ # Deviate from S26 by matching some Perl 5 Pod as well as Perl 6 Pod
regex section { [ <ambient> | <pod5> | <pod6> ] {*} }
regex ambient { ^^ ( <-[=]> .*? ) $$ \n? <?before [ ^^ '=' | $ ] > {*} }
# S26:62 three block styles: delimited, paragraph, abbreviated
# This does only two so far.
- regex pod6 { [ <p6delim> | <p6para> ] {*} }
- regex p6delim { ^^ '=begin pod' \n <content> \n '=end pod' $$ \n? {*} }
- regex p6para { ^^ '=for pod' \n <content> {*} }
+ regex pod6 { [ <p6delim> | <p6para> ]+ {*} }
+ regex p6delim { ^^'=begin ' ( <typename> ) \n
+ <content> \n
+ '=end ' $0 $$
+ \n?
+ {*}
+ }
+ regex p6para { ^^ '=for ' <typename> \n <content> {*} }
+ regex typename{ code | head\d | para | pod | table }
# Deviate from S26:207: instead of a Pod 6 abbreviated block,
- # '=pod' matches a subset of Pod 5.
+ # '=pod' can match a subset of Pod 5.
regex pod5 { ^^ '=pod' \n\n <content> \n '=cut' $$ \n? {*} }
regex content {
- .*? # all of Pod 6 TODO
- <?before [ # lookahead prevents unnecessary backtracking
- ^^ \n | # blank line ends paragraph style block
+ .*? # all of Pod 6 TODO :-)
+ <?before [ # lookahead avoids unnecessary backtracking
+ ^^$$ | # blank line ends paragraph style block
\n? ^^ '=' | # directive ends delimited style block
$ # end of file ends anything
] >
{*}
}
}
-# :-) utility methods to mix in to an emitter class
+# methods useful to an emitter class
role Pod::Tree::Parser {
# attributes, alphabetically
has Bool $!buf_out_enable = Bool::True; # for Z<> to suppress output
View
@@ -19,9 +19,9 @@ class Pod::Tree::Pod5 does Pod::Tree::Parser {
make "ambient $ambient\n";
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make ~ $/<p6delim>[0].ast; }
+ elsif defined($/<p6para>) { make ~ $/<p6para>[0].ast; }
+ elsif defined($/<p6abbr>) { make ~ $/<p6abbr>[0].ast; }
}
method p6delim($/) {
my Str $p6 = ~ $/<content>.ast;
View
@@ -19,9 +19,9 @@ class Pod::Tree::Pod6 does Pod::Tree::Parser {
make "ambient $ambient\n";
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make ~ $/<p6delim>[0].ast; }
+ elsif defined($/<p6para>) { make ~ $/<p6para>[0].ast; }
+ elsif defined($/<p6abbr>) { make ~ $/<p6abbr>[0].ast; }
}
method p6delim($/) {
my Str $p6 = ~ $/<content>.ast;
View
@@ -19,9 +19,9 @@ class Pod::Tree::Text does Pod::Tree::Parser {
make "ambient $ambient\n";
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make ~ $/<p6delim>[0].ast; }
+ elsif defined($/<p6para>) { make ~ $/<p6para>[0].ast; }
+ elsif defined($/<p6abbr>) { make ~ $/<p6abbr>[0].ast; }
}
method p6delim($/) {
my Str $p6 = ~ $/<content>.ast;
View
@@ -31,9 +31,9 @@ class Pod::Tree::Xhtml does Pod::Tree::Parser {
make "<!--ambient $ambient -->\n";
}
method pod6($/) {
- if defined($/<p6delim>) { make ~ $/<p6delim>.ast; }
- elsif defined($/<p6para>) { make ~ $/<p6para>.ast; }
- elsif defined($/<p6abbr>) { make ~ $/<p6abbr>.ast; }
+ if defined($/<p6delim>) { make ~ $/<p6delim>[0].ast; }
+ elsif defined($/<p6para>) { make ~ $/<p6para>[0].ast; }
+ elsif defined($/<p6abbr>) { make ~ $/<p6abbr>[0].ast; }
}
method p6delim($/) {
my Str $p6 = ~ $/<content>.ast;
View
@@ -7,21 +7,19 @@ multi sub eq_or_diff($received, $expected, Str $desc) is export()
is( $received, $expected, $desc ); # from module Test
if $received ne $expected {
+ my @expected = $expected.split("\n");
+ my @received = $received.split("\n");
say "# failed $desc";
say "#### expected: " ~ "-" x 20;
- my @expected = $expected.split("\n");
- my $i = 0;
- say @expected.map({"#" ~ $i++ ~ "## $_"}).join("\n");
+ for 0 .. @expected.elems-1 -> $i {
+ say "#$i## {@expected[$i]}";
+ }
say "#### received: " ~ "-" x 20;
- my @received = $received.split("\n");
- $i = 0;
- while $i < @received.elems {
- my $status = "!=";
- if $i < @expected.elems and @received[$i] eq @expected[$i] {
- $status = "==";
- }
+ for 0 .. @received.elems-1 -> $i {
+ my $status =
+ ( $i < @expected.elems and @received[$i] eq @expected[$i] )
+ ?? "==" !! "!=";
say "#$i$status {@received[$i]}";
- $i++;
}
}
}
View
0 lib/Test/Harness.pm 100755 → 100644
No changes.
@@ -1,6 +1,6 @@
#!/usr/local/bin/perl6
use Test::Differences;
-use Pod::Tree::Test; # diagnotic trace emitter for Perl 6 tree based Pod parser
+use Pod::Tree::Diag; # diagnotic trace emitter for Perl 6 tree based Pod parser
plan 3;
@@ -19,7 +19,7 @@ eq_or_diff( $received, $expected, 'p01-delim.pod delimited style' );
$received = Pod::Tree::Test.parsefile('t/p01-para.pod');
$expected = 'doc beg test
ambient #!perl6
-ambient say "any Perl 6 code";
+ambient say "Perl code";
blk beg pod PARAGRAPH version=>6
blk beg para PARAGRAPH
content Paragraph style first,
@@ -29,14 +29,14 @@ blk end pod PARAGRAPH
blk beg pod PARAGRAPH version=>6
blk beg para PARAGRAPH
content Paragraph style second,
-content ended by blank line.
+content until blank line.
blk end para PARAGRAPH
blk end pod PARAGRAPH
-ambient say "more Perl 6";
+ambient say "more Perl";
blk beg pod PARAGRAPH version=>6
blk beg para PARAGRAPH
content Paragraph style third,
-content ended by end of file.
+content until end of file.
blk end para PARAGRAPH
blk end pod PARAGRAPH
doc end';
View
@@ -1,14 +1,14 @@
#!perl6
-say "any Perl 6 code";
+say "Perl code";
=for pod
Paragraph style first,
ended by Pod directive.
=for pod
Paragraph style second,
-ended by blank line.
+until blank line.
-say "more Perl 6";
+say "more Perl";
=for pod
Paragraph style third,
-ended by end of file.
+until end of file.

0 comments on commit b8a625a

Please sign in to comment.