Skip to content

Commit

Permalink
Make grammar externally accessible, lazily-built but stateful:
Browse files Browse the repository at this point in the history
This is useful so you can prod and adjust the grammar before the
grammar object is created.

I hate that we use a class method without an instance or allow
clearing or accessing the grammar object once we build it, but at
the very least, we now allow the string to be accessed and updated
before the grammar is created. We also cache it now with a stateful
variable.
  • Loading branch information
xsawyerx committed May 30, 2022
1 parent 79bd3c0 commit 2426e8f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/Guacamole.pm
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package Guacamole;

use strict;
use warnings;
use feature qw< state >;
use constant {
'DEBUG' => 0,
};

use Marpa::R2;

my $grammar_source = q{
our $grammar_source = q{
lexeme default = latm => 1
:default ::= action => [ name, start, length, values ]
Expand Down Expand Up @@ -2101,7 +2102,6 @@ whitespace ~ [\s]+
};
our $grammar = Marpa::R2::Scanless::G->new({ source => \$grammar_source });
sub build_struct {
my ( $rec, $initial_valueref ) = @_;
Expand Down Expand Up @@ -2141,6 +2141,8 @@ sub build_struct {
sub parse {
my ($class, $text) = @_;
state $grammar = Marpa::R2::Scanless::G->new({ source => \$grammar_source });
my %args = (
'grammar' => $grammar,
Expand Down

0 comments on commit 2426e8f

Please sign in to comment.