AST/Grammar/ECMAScript_262_5/Pattern.pm

filter: Statementstmt 48.3% 29 / 60 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 53.3% 8 / 15 Podpod 100% 6 / 6 totaltotal 48.8% 43 / 88 CC 5 SCAR 15.6
CC
5
Cov
44%
new
12.0
_eventCallback
12.0
make_grammar_content
2.0
CRAP 4.7
« AST/Impl/Logger.pm ↑ Summary AST/Impl/Singleton.pm »
1 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 5 ▶use warnings FATAL => 'all';
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern;
5 5 ▶use parent qw/MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Base/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 ▶use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 5 ▶use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 5 ▶use SUPER;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 ▶use Scalar::Util qw/blessed/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # ABSTRACT: ECMAScript-262, Edition 5, pattern grammar written in Marpa BNF
13  
14 5 our $VERSION = '0.020'; # VERSION
15  
16  
17 #
18 # Note that this grammar is NOT supposed to be injected in Program
19 #
20 5 our $grammar_content = do {local $/; <DATA>};
21  
22  
23 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
24 0 my ($class, $optionsp) = @_;
25  
26 0 ▶ $optionsp //= {};
Condition0%0/2
$optionsp //= {}
l!l
00
MC/DC0%0/1
$optionsp //= {}
$optionsp
Truth table0%0/2
A
A= $optionsp
Aresult
11
00
27  
28 0 ▶ my $semantics_package = exists($optionsp->{semantics_package}) ? $optionsp->{semantics_package} : join('::', $class, 'Semantics');
Branch: 1 branch
BranchTrueFalseTotal
exists $optionsp->{'semantics_package'} ? : 0 0 0
29  
30 0 my $self = $class->SUPER();
31  
32 #
33 # Add semantics package to self
34 #
35 0 $self->{_semantics_package} = $semantics_package;
36 #
37 # Add tracking of disjunction positions
38 #
39 0 $self->{_lparen} = [];
40  
41 0 return $self;
42 }
43  
44  
45 0 ▶sub make_grammar_content {
Subroutine make_grammar_content: not called CC=1 SCAR=6.9
Pod documented
46 0 my ($class) = @_;
47 0 return $grammar_content;
48 }
49  
50  
51 0 ▶sub lparen {
Subroutine lparen: not called CC=1 SCAR=6.9
Pod documented
52 0 my ($self) = @_;
53  
54 0 return $self->{_lparen};
55 }
56  
57  
58 0 ▶sub recce_option {
Subroutine recce_option: not called CC=1 SCAR=6.9
Pod documented
59 0 my ($self) = @_;
60 #
61 # Get default hash
62 #
63 0 my $default = $self->SUPER();
64 #
65 # And overwrite the semantics_package
66 #
67 0 $default->{semantics_package} = $self->{_semantics_package};
68  
69 0 return $default;
70 }
71  
72  
73 0 ▶sub parse {
Subroutine parse: not called CC=1 SCAR=6.9
Pod documented
74 0 my ($self, $source, $impl) = @_;
75 #
76 # Reset tracking of disjunction positions
77 #
78 0 $self->{_lparen} = [];
79 0 return $self->SUPER($source, $impl,
80 {
81 callback => \&_eventCallback,
82 callbackargs => [ $self ],
83 });
84 }
85  
86 0 ▶sub _eventCallback {
Subroutine _eventCallback: not called CC=3 SCAR=24.8
87 0 my ($self, $source, $pos, $max, $impl) = @_;
88  
89 #
90 # $pos is the exact position where SLIF stopped because of an event
91 #
92 0 my $rc = $pos;
93  
94 0 foreach (@{$impl->events()}) {
95 0 my ($name) = @{$_};
96 #
97 # Events are always in this order:
98 #
99 # ---------------------------------
100 # 1. Completion events first (XXX$)
101 # ---------------------------------
102 #
103 0 ▶ if ($name eq 'LPAREN_ATOM_DISJUNCTION$') {
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "LPAREN_ATOM_DISJUNCTION\$") 0 0 0
104 #
105 # By definition, the current position here is exactly
106 # after the '(', so position in the stream of this
107 # lexeme is $pos-1.
108 0 push(@{$self->{_lparen}}, $pos-1);
109 }
110 }
111  
112 0 return $rc;
113 }
114  
115  
116 0 ▶sub value {
Subroutine value: not called CC=1 SCAR=6.9
Pod documented
117 0 my ($self, $impl) = @_;
118  
119 #
120 # Left-parenthesis locations, so that they are visible when Marpa will call
121 # semantics_package's new().
122 #
123 0 local $MarpaX::Languages::ECMAScript::AST::Grammar::Pattern::lparen = $self->{_lparen};
124  
125 0 return $self->SUPER($impl);
126 }
127  
128  
129  
130 5 1;
131  
132 =pod
133  
134 =encoding UTF-8
135  
136 =head1 NAME
137  
138 MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern - ECMAScript-262, Edition 5, pattern grammar written in Marpa BNF
139  
140 =head1 VERSION
141  
142 version 0.020
143  
144 =head1 SYNOPSIS
145  
146 use strict;
147 use warnings FATAL => 'all';
148 use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern;
149  
150 my $grammar = MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern->new();
151  
152 my $grammar_content = $grammar->content();
153 my $grammar_option = $grammar->grammar_option();
154 my $recce_option = $grammar->recce_option();
155  
156 =head1 DESCRIPTION
157  
158 This modules returns describes the ECMAScript 262, Edition 5 pattern grammar written in Marpa BNF, as of L<http://www.ecma-international.org/publications/standards/Ecma-262.htm>, section 15.10.1. This module inherits the methods from MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Base package.
159  
160 =head1 SUBROUTINES/METHODS
161  
162 =head2 new($optionsp)
163  
164 $optionsp is a reference to hash that may contain the following key/value pair:
165  
166 =over
167  
168 =item semantics_package
169  
170 As per Marpa::R2, The semantics package is used when resolving action names to fully qualified Perl names. This package must support and behave as documented in the Semantics package (c.f. SEE ALSO).
171  
172 =back
173  
174 =head2 make_grammar_content($class)
175  
176 Returns the grammar. This will be injected in the Program's grammar.
177  
178 =head2 lparen($self)
179  
180 Returns current lexer left parenthesis offsets of captures.
181  
182 =head2 recce_option($self)
183  
184 Returns option for Marpa::R2::Scanless::R->new(), returned as a reference to a hash.
185  
186 =head2 parse($self, $source, $impl)
187  
188 Parse the source given as $source using implementation $impl.
189  
190 =head2 value($self, $impl)
191  
192 Return the parse tree (unique) value. $impl is the recognizer instance for the grammar. Will raise an InternalError exception if there is no parse tree value, or more than one parse tree value. Please note that this method explicity destroys the recognizer using $impl->destroy_R. Value itself is an AST where every string is a perl string. This a subclass of MarpaX::Languages::ECMAScript::AST::Grammar::Base::value() because the position of disjunction left parenthesis is localized, so that value() will see them.
193  
194 This method is explicitely setting a localized MarpaX::Languages::ECMAScript::AST::Grammar::Pattern::lparen variable that is an array reference of all disjunctions left parenthesis locations in the regular expression perl string.
195  
196 =head1 SEE ALSO
197  
198 L<MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Base>
199  
200 L<MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics>
201  
202 =head1 AUTHOR
203  
204 Jean-Damien Durand <jeandamiendurand@free.fr>
205  
206 =head1 COPYRIGHT AND LICENSE
207  
208 This software is copyright (c) 2013 by Jean-Damien Durand.
209  
210 This is free software; you can redistribute it and/or modify it under
211 the same terms as the Perl 5 programming language system itself.
212  
213 =cut
214  
215 __DATA__
« AST/Impl/Logger.pm ↑ Summary AST/Impl/Singleton.pm »