—# 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
=head1 Name
Marpa::R2::Scanless::G - Scanless interface grammars
=head1 Synopsis
=for Marpa::R2::Display
name: Scanless grammar synopsis
partial: 1
normalize-whitespace: 1
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
}
);
=for Marpa::R2::Display::End
=head1 About this document
This page is the reference for the grammar objects
of Marpa's Scanless interface.
=head1 Constructor
The C<new()> method is the constructor for Scanless grammars.
An example of its use is L<above|/"Synopsis">.
The C<new()> constructor accepts a hash of named arguments.
The following named arguments are allowed:
=head2 action_object
Specifies the C<action_object> named argument that
will be used for the G1 grammar.
For details, see L<Marpa::R2::Grammar/"action_object">.
=head2 bless_package
Specifies the name of a Perl package.
The package is used
for blessing node values into a Perl class,
in conjunction with the
L<C<bless> adverb|Marpa::R2::Scanless::DSL/"bless">.
=head2 default_action
Specifies the C<default_action> named argument that
will be used for the G1 grammar.
For details, see L<Marpa::R2::Grammar/"default_action">.
=head2 source
The value of the C<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 L<in its own
document|Marpa::R2::Scanless::DSL>.
=head2 trace_file_handle
The value is a file handle.
Trace output and warning messages
go to the trace file handle.
By default the trace file handle is C<STDERR>.
=head1 Accessor
=head2 rule()
Given a G1 rule ID as its argument,
returns an array containing the
names of the symbols of that rule.
The C<rule()> method
returns a Perl false if no G1 rule with that rule ID exists.
If the rule ID exists,
C<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 C<rule()> corresponds to the C<rule()> method
of grammars in Marpa's standard interface.
The SLIF's C<rule()> method is useful in
combination with
the SLIF's
of L<the progress method|Marpa::R2::Scanless::R/progress()>,
whose output identifies rules by rule ID.
=head1 Trace method
=head2 show_rules()
=for Marpa::R2::Display
name: Scanless show_rules() synopsis
partial: 1
normalize-whitespace: 1
my $show_rules_output = $grammar->show_rules();
=for Marpa::R2::Display::End
The C<show_rules()> method is the equivalent of
calling L<Marpa::R2::Grammar's show_rules()
method|Marpa::R2::Grammar/"show_rules()">
for both the G0 and G1 grammars.
It is useful for showing the rules as they will
appear in trace and debugging outputs.
=head1 Copyright and License
=for Marpa::R2::Display
ignore: 1
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
=for Marpa::R2::Display::End
=cut
# Local Variables:
# mode: cperl
# cperl-indent-level: 4
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4: