lib/Data/SExpression/Parser.yp

filter: Statementstmt 92.4% 49 / 53 Branchbran 72.7% 16 / 22 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 19 / 19 Podpod 0.0% 0 / 8 totaltotal 83.1% 89 / 107 CC 14 SCAR 15.4
CC
14
Cov
87%
lexer
11.1
set_input
2.0
set_handler
2.0
CRAP 4.7
« blib/lib/Data/SExpression/Parser.pm ↑ Summary blib/lib/Data/SExpression/Symbol.pm »
1 # -*- mode: perl -*-
2 #
3 # Parser.yp
4 #
5 # Grammar to parse SExpressions for Data::SExpression
6 #
7 #
8  
9 %{
10 9 ▶use Data::SExpression::Cons;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 9 ▶use Scalar::Util qw(weaken);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 %}
13  
14 25 ▶%%
Subroutine new: called CC=2 SCAR=7.0
Pod undocumented
15 25  
16 25 ▶sexpression: expression { $_[0]->YYAccept; return $_[1]; }
Subroutine __ANON__: called CC=1 SCAR=0.1
Branch: 1 branch
BranchTrueFalseTotal
ref $class and $class = ref $class 0 25 25
17 ;
18  
19 expression: NUMBER
20 61 ▶ | SYMBOL { $_[0]->handler->new_symbol($_[1]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
21 12 ▶ | STRING { $_[0]->handler->new_string($_[1]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
22 | list
23 | quoted
24  
25 ;
26  
27 60 ▶list: '(' list_interior ')' { $_[2] }
Subroutine __ANON__: called CC=1 SCAR=0.0
28 ;
29  
30  
31 list_interior:
32 0 ▶ expression '.' expression { $_[0]->handler->new_cons($_[1], $_[3]) }
Subroutine __ANON__: called CC=1 SCAR=1.2
33 50 ▶ | expression list_interior { $_[0]->handler->new_cons($_[1], $_[2]) }
Subroutine __ANON__: called CC=1 SCAR=0.0
34 37 ▶ | expression { $_[0]->handler->new_cons($_[1], undef) }
Subroutine __ANON__: called CC=1 SCAR=0.0
35 10 ▶ | { undef }
Subroutine __ANON__: called CC=1 SCAR=0.0
36  
37 ;
38  
39 quoted:
40 7 ▶ QUOTE expression { $_[0]->handler->new_cons($_[0]->handler->new_symbol($_[1]),
Subroutine __ANON__: called CC=1 SCAR=0.0
41 $_[0]->handler->new_cons($_[2], undef))}
42 25 ;
43  
44 %%
45 25  
46 67 ▶sub set_input {
Subroutine set_input: called CC=2 SCAR=7.0
Pod undocumented
47 67 my $self = shift;
48 67 my $input = shift;
49 67 ▶ die(__PACKAGE__ . "::set_input called with 0 arguments") unless defined($input);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $input 0 67 67
50 67 $self->YYData->{INPUT} = $input;
51 }
52  
53 12 ▶sub set_handler {
Subroutine set_handler: called CC=2 SCAR=7.0
Pod undocumented
54 12 my $self = shift;
55 12 ▶ my $handler = shift or die(__PACKAGE__ . "::set_handler called with 0 arguments");
Branch: 1 branch
BranchTrueFalseTotal
my $handler = shift() or die "Data::SExpression::Parser::set_handler called with 0 arguments" 12 0 12
56 12 $self->YYData->{HANDLER} = $handler;
57 12 weaken $self->YYData->{HANDLER};
58 }
59  
60 194 ▶sub handler {
Subroutine handler: called CC=1 SCAR=0.0
Pod undocumented
61 194 my $self = shift;
62 194 return $self->YYData->{HANDLER};
63 }
64  
65 54 ▶sub unparsed_input {
Subroutine unparsed_input: called CC=1 SCAR=0.0
Pod undocumented
66 54 my $self = shift;
67 54 return substr($self->YYData->{INPUT}, pos($self->YYData->{INPUT}));
68 }
69  
70  
71 0 my %quotes = (q{'} => 'quote',
72 q{`} => 'quasiquote',
73 q{,} => 'unquote');
74  
75  
76 305 ▶sub lexer {
Subroutine lexer: called CC=11 SCAR=24.1
Pod undocumented
77 305 my $self = shift;
78  
79 305 ▶ defined($self->YYData->{INPUT}) or return ('', undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $self->YYData->{"INPUT"} or return "", undef 305 0 305
80  
81 305 my $symbol_char = qr{[*!\$[:alpha:]\?<>=/+:_{}-]};
82  
83 305 for($self->YYData->{INPUT}) {
84 305 $_ =~ /\G \s* (?: ; .* \s* )* /gcx;
85  
86 305 ▶ /\G ([+-]? \d+ (?:[.]\d*)?) /gcx
Branch: 1 branch
BranchTrueFalseTotal
/\G ([+-]? \d+ (?:[.]\d*)?) /cgx || /\G ([+-]? [.] \d+) /cgx and return "NUMBER", $1 38 267 305
Condition100%3/3
/\G ([+-]? \d+ (?:[.]\d*)?) /cgx or /\G ([+-]? [.] \d+) /cgx
l!l&&r!l&&!r
371267
MC/DC100%2/2
/\G ([+-]? \d+ (?:[.]\d*)?) /cgx or /\G ([+-]? [.] \d+) /cgx
/\G ([+-]? \d+ (?:[.]\d*)?) /cgx /\G ([+-]? [.] \d+) /cgx
Truth table100%3/3
A or B
A= /\G ([+-]? \d+ (?:[.]\d*)?) /cgxB= /\G ([+-]? [.] \d+) /cgx
ABresult
1X1
011
000
87 || /\G ([+-]? [.] \d+) /gcx
88 and return ('NUMBER', $1);
89  
90 267 ▶ /\G ($symbol_char ($symbol_char | \d | [.] )*)/gcx
Branch: 1 branch
BranchTrueFalseTotal
/\G ($symbol_char ($symbol_char | \d | [.] )*)/cgx and return "SYMBOL", $1 66 201 267
91 and return ('SYMBOL', $1);
92  
93 201 ▶ /\G (\| [^|]* \|) /gcx
Branch: 1 branch
BranchTrueFalseTotal
/\G (\| [^|]* \|) /cgx and return "SYMBOL", $1 0 201 201
94 and return ('SYMBOL', $1);
95  
96 201 ▶ /\G " ([^"\\]* (?: \\. [^"\\]*)*) "/gcx
Branch: 2 branches
BranchTrueFalseTotal
/\G " ([^"\\]* (?: \\. [^"\\]*)*) "/cgx and return "STRING", defined $1 ? $1 : "" 28 173 201
defined $1 ? : 28 0 28
97 and return ('STRING', defined($1) ? $1 : "");
98  
99 173 ▶ /\G ([().])/gcx
Branch: 1 branch
BranchTrueFalseTotal
/\G ([().])/cgx and return $1, $1 150 23 173
100 and return ($1, $1);
101  
102 /\G ([`',]) /gcx
103 23 ▶ and return ('QUOTE', $quotes{$1});
Branch: 1 branch
BranchTrueFalseTotal
/\G ([`',]) /cgx and return "QUOTE", $quotes{$1} 8 15 23
104  
105 15 return ('', undef);
106 }
107 }
108  
109 1 ▶sub error {
Subroutine error: called CC=1 SCAR=0.2
Pod undocumented
110 1 my $self = shift;
111 1 my ($tok, $val) = $self->YYLexer->($self);
112 1 die("Parse error near: '" . $self->unparsed_input . "'");
113 0 return undef;
114 }
115  
116 54 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
117 54 my $self = shift;
118 54 return $self->YYParse(yylex => \&lexer, yyerror => \&error);
119 }
« blib/lib/Data/SExpression/Parser.pm ↑ Summary blib/lib/Data/SExpression/Symbol.pm »