Marpa::R2::Scanless::G - Scanless interface grammars
my $grammar = Marpa::R2::Scanless::G->new( { action_object => 'My_Actions', default_action => 'do_first_arg', source => \(<<'END_OF_SOURCE'), :start ::= Script Script ::= Expression+ separator => comma action => do_script comma ~ [,] Expression ::= Number | '(' Expression ')' action => do_parens assoc => group || Expression '**' Expression action => do_pow assoc => right || Expression '*' Expression action => do_multiply | Expression '/' Expression action => do_divide || Expression '+' Expression action => do_add | Expression '-' Expression action => do_subtract Number ~ [\d]+ :discard ~ whitespace whitespace ~ [\s]+ # allow comments :discard ~ <hash comment> <hash comment> ~ <terminated hash comment> | <unterminated final hash comment> <terminated hash comment> ~ '#' <hash comment body> <vertical space char> <unterminated final hash comment> ~ '#' <hash comment body> <hash comment body> ~ <hash comment char>* <vertical space char> ~ [\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}] <hash comment char> ~ [^\x{A}\x{B}\x{C}\x{D}\x{2028}\x{2029}] END_OF_SOURCE } );
This page is the reference for the grammar objects of Marpa's Scanless interface.
The new() method is the constructor for Scanless grammars. An example of its use is above. The new() constructor accepts a hash of named arguments. The following named arguments are allowed:
new()
Specifies the action_object named argument that will be used for the G1 grammar. For details, see "action_object" in Marpa::R2::NAIF::Grammar.
action_object
Specifies the name of a Perl package. The package is used for blessing node values into a Perl class, in conjunction with the bless adverb.
bless
Specifies the default_action named argument that will be used for the G1 grammar. For details, see "default_action" in Marpa::R2::NAIF::Grammar.
default_action
The value of the source named argument must be a reference to a string which contains a description of the grammar. The string's format is a domain-specific language, described in its own document.
source
The value is a file handle. Trace output and warning messages go to the trace file handle. By default the trace file handle is STDERR.
STDERR
$slg->set( { trace_file_handle => $trace_fh } );
This method allows the named arguments to be changed after an SLIF grammar is created. Currently, the only argument that may be changed in trace_file_handle.
trace_file_handle
my @g1_rule_ids = $slg->g1_rule_ids(); for my $g1_rule_id (@g1_rule_ids) { $g1_rules_description .= "$g1_rule_id " . ( join q{ }, map {"<$_>"} $slg->rule($g1_rule_id) ) . "\n"; }
Returns a list of the G1 rule ID's. The symbols for these can be queried using the the SLIF grammar's rule() method,
my @g0_rule_ids = $slg->g0_rule_ids(); for my $g0_rule_id (@g0_rule_ids) { $g0_rules_description .= "$g0_rule_id " . ( join q{ }, map {"<$_>"} $slg->g0_rule($g0_rule_id) ) . "\n"; }
Given a G0 rule ID as its argument, returns an array containing the names of the symbols of that rule. The g0_rule() method returns a Perl false if no G0 rule with that rule ID exists. If the G0 rule ID exists, g0_rule() returns a list of one or more symbol names. The first symbol name will be that of the rule's LHS symbol. The rest of the list will be the names of the rule's RHS symbols, in order.
g0_rule()
Returns a list of the G0 rule ID's. The symbols for these can be queried using the the SLIF grammar's g0_rule() method,
my $show_rules_output = $slg->show_rules();
$show_rules_output .= $slg->show_rules(3, 'G0');
The show_rules() method returns a descripton of the rules for a subgrammar, by default G1. It is useful for understanding the rules as they appear in trace and debugging outputs. To allow for improvements in Marpa::R2, the output of show_rules() is subject to change.
show_rules()
The first optional argument can be a numeric verbosity level. The default verbosity is 1, which is adequate for most purposes. A verbosity of 2 prints additional information useful for those new to SLIF tracing and debugging. A verbosity of 3 prints additional information for experts, for those new to SLIF tracing and debugging.
The second, optional, argument is the name of a subgrammar. Currently there are G0 and G1 subgrammars.
$show_symbols_output .= $slg->show_symbols(3);
$show_symbols_output .= $slg->show_symbols(3, 'G0');
The show_symbols() method returns a descripton of the symbols for a subgrammar, by default G1. It is useful for understanding the symbols as they appear in trace and debugging outputs. To allow for improvements in Marpa::R2, the output of show_symbols() is subject to change.
show_symbols()
The first argument can be a numeric verbosity level. The default verbosity is 1, which is adequate for most purposes. A verbosity of 2 prints additional information useful for those new to SLIF tracing and debugging. A verbosity of 3 prints additional information for experts, for those new to SLIF tracing and debugging.
Discouraged methods are those that continue to be supported, but their use is discouraged for one reason or another.
Given a G1 rule ID as its argument, returns an array containing the names of the symbols of that rule. The rule() method returns a Perl false if no G1 rule with that rule ID exists. If the rule ID exists, rule() returns a list of one or more symbol names. The first symbol name will be that of the rule's LHS symbol. The rest of the list will be the names of the rule's RHS symbols, in order. The SLIF's rule() method is useful in combination with the SLIF's of the progress method, whose output identifies rules by rule ID.
rule()
Copyright 2013 Jeffrey Kegler This file is part of Marpa::R2. Marpa::R2 is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Marpa::R2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with Marpa::R2. If not, see http://www.gnu.org/licenses/.
To install Marpa::R2, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Marpa::R2
CPAN shell
perl -MCPAN -e shell install Marpa::R2
For more information on module installation, please visit the detailed CPAN module installation guide.