Pugs/Grammar/Operator.pm untested

filter: Statementstmt 0.0% 0 / 51 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 15 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 72 CC 2 SCAR 9.2
CC
2
Cov
0%
recompile
6.0
BEGIN
2.0
add_rule
2.0
CRAP 2.5
1 package Pugs::Grammar::Operator;
2 use strict;
3 use warnings;
4 use base qw(Pugs::Grammar::BaseCategory);
5 use Pugs::Grammar::Precedence;
6  
7 use Data::Dumper;
8  
9 our $operator;
10  
11 # TODO - implement the "magic hash" dispatcher
12 our %hash;
13  
14 #our @subroutine_names;
15  
16 BEGIN {
17 $operator = Pugs::Grammar::Precedence->new(
18 grammar => 'Pugs::Grammar::Operator',
19 header => q!
20
21 attr:
22 #empty
23 { $_[0]->{out}= { attribute => [] } }
24 | BAREWORD BAREWORD attr
25 { $_[0]->{out}= {
26 attribute => [
27 [$_[1], $_[2],],
28 @{$_[3]{attribute}},
29 ],
30 } }
31 ;
32
33 exp:
34 NUM
35 { $_[0]->{out}= $_[1] }
36  
37 | '@' '(' exp ')'
38 { $_[0]->{out}= { op1 => 'array_context', exp1 => $_[3], } }
39  
40 | BAREWORD
41 { $_[0]->{out}= { op1 => 'call', sub => $_[1], } }
42 | BAREWORD exp %prec P003
43 { $_[0]->{out}= { op1 => 'call', sub => $_[1], param => $_[2], } }
44
45 | DOT_BAREWORD exp %prec P003
46 { $_[0]->{out}= { op1 => 'method_call', self => { 'scalar' => '$_' }, method => $_[1], param => $_[2], } }
47 | DOT_BAREWORD %prec P003
48 { $_[0]->{out}= { op1 => 'method_call', self => { 'scalar' => '$_' }, method => $_[1], } }
49  
50 | MY NUM attr
51 { $_[0]->{out}= {
52 op1 => { op => $_[1]{op} },
53 fixity => 'prefix',
54 exp1 => $_[2],
55 %{$_[3]}, } }
56 | MY BAREWORD NUM attr
57 { $_[0]->{out}= {
58 op1 => { op => $_[1]{op} },
59 fixity => 'prefix',
60 exp1 => $_[3],
61 type => { bareword => $_[2], },
62 %{$_[4]}, } }
63  
64 !,
65 );
66 # print "created operator table\n";
67 }
68  
69 sub add_rule {
70 # print "add operator\n";
71 my $self = shift;
72 my %opt = @_;
73 # print "Operator add: @{[ %opt ]} \n";
74  
75 delete $opt{rule};
76 $operator->add_op( \%opt );
77
78 #push @subroutine_names, $opt{name};
79 }
80  
81 use Pugs::Grammar::Infix;
82 use Pugs::Grammar::Prefix;
83 use Pugs::Grammar::Postfix;
84 use Pugs::Grammar::Circumfix;
85 use Pugs::Grammar::Postcircumfix;
86 use Pugs::Grammar::Ternary;
87  
88 sub recompile {
89 my $class = shift;
90  
91 # tokenizer
92 %hash = (
93 %Pugs::Grammar::Infix::hash,
94 %Pugs::Grammar::Prefix::hash,
95 %Pugs::Grammar::Postfix::hash,
96 %Pugs::Grammar::Circumfix::hash,
97 %Pugs::Grammar::Postcircumfix::hash,
98 %Pugs::Grammar::Ternary::hash,
99 );
100 $class->SUPER::recompile;
101  
102 {
103 #no warnings 'recursion'; # doesn't seem to work here
104 local $SIG{'__WARN__'} =
105 sub {
106 warn $_[0] if $_[0] !~ /recursion/
107 };
108 #warn 'compiling grammar';
109 # operator-precedence
110 my $g = $operator->emit_yapp;
111 #print $g;
112 my $p;
113 $p = $operator->emit_grammar_perl5;
114 #print $p;
115 eval $p;
116 #warn 'compiled grammar';
117 }
118 }
119  
120 BEGIN {
121 #~ __PACKAGE__->add_rule(
122 #~ # tokenizer defined in Term.pm
123 #~ name => 'CALL',
124 #~ name2 => ')',
125 #~ assoc => 'non',
126 #~ precedence => 'tighter',
127 #~ other => '*',
128 #~ );
129  
130 __PACKAGE__->recompile;
131 }
132  
133 1;