File Coverage

blib/lib/MarpaX/Languages/ECMAScript/AST/Grammar/ECMAScript_262_5/Pattern.pm
Criterion Covered Total %
statement 24 55 43.6
branch 0 4 0.0
condition 0 2 0.0
subroutine 8 15 53.3
pod 6 6 100.0
total 38 82 46.3


line stmt bran cond sub pod time code
1 1     1   4 use strict;
  1         2  
  1         37  
2 1     1   4 use warnings FATAL => 'all';
  1         2  
  1         51  
3              
4             package MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern;
5 1     1   4 use parent qw/MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Base/;
  1         2  
  1         8  
6 1     1   543 use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::Pattern::Semantics;
  1         2  
  1         54  
7 1     1   10 use MarpaX::Languages::ECMAScript::AST::Grammar::ECMAScript_262_5::CharacterClasses;
  1         2  
  1         28  
8 1     1   7 use SUPER;
  1         2  
  1         77  
9 1     1   8 use Carp qw/croak/;
  1         2  
  1         63  
10 1     1   7 use Scalar::Util qw/blessed/;
  1         1  
  1         660  
11              
12             # ABSTRACT: ECMAScript-262, Edition 5, pattern grammar written in Marpa BNF
13              
14             our $VERSION = '0.019'; # VERSION
15              
16              
17             #
18             # Note that this grammar is NOT supposed to be injected in Program
19             #
20             our $grammar_content = do {local $/; };
21              
22              
23             sub new {
24 0     0 1   my ($class, $optionsp) = @_;
25              
26 0   0       $optionsp //= {};
27              
28 0 0         my $semantics_package = exists($optionsp->{semantics_package}) ? $optionsp->{semantics_package} : join('::', $class, 'Semantics');
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             sub make_grammar_content {
46 0     0 1   my ($class) = @_;
47 0           return $grammar_content;
48             }
49              
50              
51             sub lparen {
52 0     0 1   my ($self) = @_;
53              
54 0           return $self->{_lparen};
55             }
56              
57              
58             sub recce_option {
59 0     0 1   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             sub parse {
74 0     0 1   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             sub _eventCallback {
87 0     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()}) {
  0            
95 0           my ($name) = @{$_};
  0            
96             #
97             # Events are always in this order:
98             #
99             # ---------------------------------
100             # 1. Completion events first (XXX$)
101             # ---------------------------------
102             #
103 0 0         if ($name eq 'LPAREN_ATOM_DISJUNCTION$') {
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);
  0            
109             }
110             }
111              
112 0           return $rc;
113             }
114              
115              
116             sub value {
117 0     0 1   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             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.019
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, 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
199              
200             L
201              
202             =head1 AUTHOR
203              
204             Jean-Damien Durand
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__