| 1 | package Grammar::Marpa; | ||||||||||||||||||||
| 2 | |||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use 5.018; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use overload ('qr' => 'regexify', fallback => 0); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | ▶ | use Marpa::R2; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | 1 | our $VERSION = '2.004'; | |||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | 1 | ▶ | sub regexify { | ||||||||||||||||||
|
Subroutine
regexify: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 14 | 1 | my ($grammar) = @_; | |||||||||||||||||||
| 15 | 1 | ▶ | use re 'eval'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 16 | 1 | return qr/(?{Grammar::Marpa::parse($grammar, "$_")})/; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 1 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=10 SCAR=29.5
Pod
documented
| |||||||||||||||||||||
| 20 | 1 | my $class = shift; | |||||||||||||||||||
| 21 | 1 | ▶ | $class = ref($class) || $class; | ||||||||||||||||||
|
Condition33%1/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table33%1/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 22 | 1 | ▶ | my $ebnf = ref($_[0]) eq 'HASH' ? undef : shift(@_); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 23 | 1 | my $pkg; | |||||||||||||||||||
| 24 | my %args; | ||||||||||||||||||||
| 25 | 1 | ▶ | if (ref ($_[-1]) eq 'HASH') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 26 | 0 | %args = %{pop(@_)}; | |||||||||||||||||||
| 27 | 0 | ▶ | $pkg = shift(@_) // (caller)[0]; | ||||||||||||||||||
|
Condition0%0/3
shift @_ // (caller)[0]
MC/DC0%0/2
shift @_ // (caller)[0]
shift @_
(caller)[0]
Truth table0%0/3
A // B
A= shift @_B= (caller)[0]
| |||||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | elsif (@_ % 2) { | ||||||||||||||||||||
| 30 | 1 | $pkg = shift; | |||||||||||||||||||
| 31 | 1 | %args = @_; | |||||||||||||||||||
| 32 | } | ||||||||||||||||||||
| 33 | else { | ||||||||||||||||||||
| 34 | 0 | $pkg = (caller)[0]; | |||||||||||||||||||
| 35 | 0 | %args = @_; | |||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | 1 | my %Gargs; | |||||||||||||||||||
| 38 | 1 | ▶ | $Gargs{ bless_package } = delete $args{ bless_package } if $args{ bless_package }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 1 | ▶ | $Gargs{ trace_file_handle } = $args{ trace_file_handle } if $args{ trace_file_handle }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 40 | 1 | ▶ | $ebnf //= delete $args{ source }; | ||||||||||||||||||
|
Condition33%1/3
$ebnf //= delete $args{"source"}
MC/DC0%0/2
$ebnf //= delete $args{"source"}
$ebnf
delete $args{"source"}
Truth table33%1/3
A //= B
A= $ebnfB= delete $args{"source"}
| |||||||||||||||||||||
| 41 | 1 | ▶ | $ebnf = $$ebnf if ref($ebnf); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 42 | 1 | my $G = Marpa::R2::Scanless::G->new({ source => \$ebnf, %Gargs }); | |||||||||||||||||||
| 43 | 1 | return bless [ $G, $pkg, \%args ] => $class; | |||||||||||||||||||
| 44 | } | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | ▶ | sub parse { | ||||||||||||||||||
|
Subroutine
parse: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||
| 47 | 1 | my ($grammar, $string) = @_; | |||||||||||||||||||
| 48 | 1 | my $R = Marpa::R2::Scanless::R->new({ grammar => $grammar->[ 0 ], semantics_package => $grammar->[ 1 ], %{$grammar->[ 2 ]} }); | |||||||||||||||||||
| 49 | 1 | $R->read(\$string); | |||||||||||||||||||
| 50 | 1 | ▶ | my $V = $R->value or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 1 | return $$V; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | package Grammar; | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | 1 | ▶ | sub Marpa { | ||||||||||||||||||
|
Subroutine
Marpa: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | 1 | return Grammar::Marpa->new(@_); | |||||||||||||||||||
| 58 | } | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 1 | 1; | |||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||