NAME

MarpaX::Languages::ECMAScript::AST::Grammar::Base - ECMAScript, grammars base package

VERSION

version 0.020

SYNOPSIS

use strict;
use warnings FATAL => 'all';
use MarpaX::Languages::ECMAScript::AST::Grammar::Base;

my $grammar = MarpaX::Languages::ECMAScript::AST::Grammar::Base->new("grammar", "My::Package", "ECMAScript_262_5");

my $grammar_content = $grammar->content();
my $grammar_option = $grammar->grammar_option();
my $recce_option = $grammar->recce_option();

DESCRIPTION

This modules returns a base package for all the ECMAScript grammars written in Marpa BNF.

SUBROUTINES/METHODS

new($class, $spec)

Instance a new object. Takes an ECMAScript specification $spec as required parameter.

content($self)

Returns the content of the grammar.

make_content($class, $spec)

Class method that return the default content of the grammar writen for specification $spec. Grammars are typically use Posix user-defined classes without the full classname; this method is making sure full classname is used; using $spec.

extract($self)

Returns the part of the grammar that can be safely extracted and injected in another.

make_grammar_option($class, $spec)

Class method that returns default grammar options for a given ECMA specification $spec.

make_grammar_content($class)

Class method that returns the grammar content. This class must be overwriten by the any package providing a grammar.

make_bless_package($class)

Class method that returns recommended bless_package grammar options.

grammar_option($self)

Returns recommended option for Marpa::R2::Scanless::G->new(), returned as a reference to a hash.

recce_option($self)

Returns recommended option for Marpa::R2::Scanless::R->new(), returned as a reference to a hash.

make_recce_option($class, $spec)

Class method that returns default recce options for a given ECMA specification $spec.

make_ranking_method($class)

Class method that returns recommended recce ranking_method

make_semantics_package($class)

Class method that returns a default recce semantics_package, doing nothing else but a new().

make_too_many_earley_items($class)

Class method that returns a default recce too_many_earley_items option, default is 0 i.e. disable them.

parse($self, $source, $impl, [$optionsp], [$start], [$length])

Parse the source given as reference to a scalar, using implementation $impl, an optional reference to a hash that can contain:

callback

Callbak Code Reference. Default is undef.

callbackargs

Reference to an array of callback routine arguments. Default is [].

failure

Failure callback Code Reference. Default is undef.

failureargs

Reference to an array of failure routine arguments. Default is [].

end

End callback Code Reference. Default is undef.

endargs

Reference to an array of end routine arguments. Default is [].

This method must be called as a super method by grammar using this package as a parent. $self must be a reference to a grammar instantiated via MarpaX::Languages::ECMAScript::AST::Grammar. The callback code will always be called with: per-callback arguments, $source, $pos (i.e. current position), $max (i.e. max position), $impl (i.e. a MarpaX::Languages::ECMAScript::AST::Impl instance). The default and failure callbacks must always return the new position in the stream, and raise a MarpaX::Languages::ECMAScript::AST::Exception::SyntaxError exception if there is an error. In the 'end' and 'failure' callbacks, $pos is not meaningful: this is the last position where external scanning restarted. You might want to look to the getLastLexeme() method. Output of the 'end' callback is ignored. Please note that this method explicitely creates a recognizer using $impl->make_R(), destroyed in case of error.

value($self, $impl, $optionsp)

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.

An optional reference to a hash that can contain:

traverser

CODE traverser callback. If setted, and ASF will be performed using this callback. Default is to called Marpa::R2's value() directly.

traverserscratchpad

Reference to a scratchpad for the traverse. Default is {}.

getLexeme($self, $lexemeHashp, $impl)

Fills a hash with latest paused lexeme:

name

Lexeme name

start

Start position

length

Length

line

Line number as per Marpa

column

Column number as per Marpa

value

Lexeme value

Returns a true value if a lexeme pause information is available.

getLastLexeme($self, $lexemeHashp, $impl)

Fills a hash with latest lexeme (whatever it is, its name is unknown):

start

Start position

length

Length

value

Lexeme value

Returns a true value if a lexeme pause information is available.

SEE ALSO

MarpaX::Languages::ECMAScript::AST::Impl

MarpaX::Languages::ECMAScript::AST::Util

AUTHOR

Jean-Damien Durand <jeandamiendurand@free.fr>

COPYRIGHT AND LICENSE

This software is copyright (c) 2013 by Jean-Damien Durand.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.