tagged release 0.7.1
[parrot.git] / t / compilers / pge / pge_examples.t
blob58f6993f9b6b37f22fb08465dc1bdc3e0e21d809
1 #! perl
2 # Copyright (C) 2001-2006, The Perl Foundation.
3 # $Id$
5 use strict;
6 use warnings;
7 use lib qw( t . lib ../lib ../../lib );
9 use Test::More;
10 use Parrot::Test tests => 2;
11 use Parrot::Test::PGE;
13 =head1 NAME
15 t/library/pge_examples.t - Parrot Grammar Engine tests of examples
17 =head1 SYNOPSIS
19     % prove t/compilers/pge/pge_examples.t
21 =cut
23 # 1
24 pir_output_is( <<'CODE', <<'OUT', "This made Parrot m4 fail" );
26 .sub 'test' :main
27   load_bytecode "PGE.pbc"
29   .local pmc p6rule
30   p6rule = compreg "PGE::Perl6Regex"
32   .local pmc rulesub_a, rulesub_b
33   rulesub_a  = p6rule( "a" )
34   rulesub_b  = p6rule( "^(<[b]>)" )
36   .local string input_string
37   input_string    = "_____________________________________________________________________"
39   rulesub_b( input_string )
41   print "ok1\n"
42   # end
44   rulesub_a( input_string )
45   print "ok2\n"
47 .end
49 CODE
50 ok1
51 ok2
52 OUT
54 # 2
55 pir_output_is( <<'CODE', <<'OUT', "parse FASTA" );
57 # Grok fasta files, which usually contain DNA, RNA or protein sequences.
58 # http://en.wikipedia.org/wiki/FASTA_format
60 .sub "example" :main
61     load_bytecode 'PGE.pbc'
62     load_bytecode 'PGE/Perl6Grammar.pbc'
64     .local string fasta_grammar
65     fasta_grammar = <<'END_FASTA_GRAMMAR'
66 grammar Bio::Fasta;
68 regex databank    { <Bio::Fasta::entry>+ }
69 regex entry       { <Bio::Fasta::desc_line> \n <Bio::Fasta::sequence> }
70 regex desc_line   { <Bio::Fasta::start_entry> <Bio::Fasta::id> \s+ <Bio::Fasta::desc> }
71 regex start_entry { \> }
72 regex id          { (\S+) }
73 regex desc        { (\N*) }
74 regex sequence    { (<-[>]>*) }
76 END_FASTA_GRAMMAR
78     .local string fasta
79     fasta = <<'END_FASTA'
80 >gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
81 LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV
82 EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG
83 LLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVIL
84 GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX
85 IENY
86 >poly_a teasing the parser with DNA
87 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
88 END_FASTA
90     .local pmc p6grammar
91     p6grammar = compreg "PGE::Perl6Grammar"
92     .local pmc code
93     ( code ) = p6grammar.'compile'(fasta_grammar, 'target'=>'PIR')
94     $P0 = compreg 'PIR'
95     $P1 = $P0(code)
96     $P1()
97     # print code
99     .local pmc fasta_rule
100     fasta_rule = get_global ['Bio::Fasta'], "databank"
101     .local pmc match
102     ( match ) = fasta_rule( fasta )
104     # TODO: Extract named or positional captures
105     print match
107 .end
109 CODE
110 >gi|5524211|gb|AAD44166.1| cytochrome b [Elephas maximus maximus]
111 LCLYTHIGRNIYYGSYLYSETWNTGIMLLLITMATAFMGYVLPWGQMSFWGATVITNLFSAIPYIGTNLV
112 EWIWGGFSVDKATLNRFFAFHFILPFTMVALAGVHLTFLHETGSNNPLGLTSDSDKIPFHPYYTIKDFLG
113 LLILILLLLLLALLSPDMLGDPDNHMPADPLNTPLHIKPEWYFLFAYAILRSVPNKLGGVLALFLSIVIL
114 GLMPFLHTSKHRSMMLRPLSQALFWTLTMDLLTLTWIGSQPVEYPYTIIGQMASILYFSIILAFLPIAGX
115 IENY
116 >poly_a teasing the parser with DNA
117 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
120 # Local Variables:
121 #   mode: cperl
122 #   cperl-indent-level: 4
123 #   fill-column: 100
124 # End:
125 # vim: expandtab shiftwidth=4: