MarpaX::ESLIF::RegexCallout - ESLIF Regex Callout
version 6.0.1
package MyRecognizerInterface; use Data::Dumper; sub new { bless { data => $_[1] }, $_[0] } sub read { 1 } sub isEof { 1 } sub isCharacterStream { 1 } sub encoding { } sub data { $_[0]->{data} } sub isWithDisableThreshold { 1 } sub isWithExhaustion { 0 } sub isWithNewline { 1 } sub isWithTrack { 0 } sub do_regexCallout { my ($self, $regexCallout) = @_; print STDERR "Regex callout: " . Dumper($regexCallout); return 0; } 1; package MyValueInterface; sub new { bless { result => undef }, $_[0] } sub isWithHighRankOnly { 1 } sub isWithOrderByRank { 1 } sub isWithAmbiguous { 0 } sub isWithNull { 0 } sub maxParses { 0 } sub setResult { $_[0]->{result} = $_[1] } sub getResult { $_[0]->{result} } 1; package main; use MarpaX::ESLIF; my $eslif = MarpaX::ESLIF->new(); my $data = do { local $/; <DATA> }; my $eslifGrammar = MarpaX::ESLIF::Grammar->new($eslif, $data); foreach (qw/123XX XX/) { my $recognizerInterface = MyRecognizerInterface->new($_); my $valueInterface = MyValueInterface->new(); $eslifGrammar->parse($recognizerInterface, $valueInterface); print STDERR "Value: " . $valueInterface->getResult() . "\n"; } __DATA__ # # This is an example of a calculator grammar # :default ::= regex-action => do_regexCallout topRule ::= /[\d]+(?C"Digits")(.*)(?C"Rest")/ topRule ::= /X+(?C123)/
ESLIF Regex Callout.
Regular expression callbacks have an argument that is hash blessed to this package. Regular expression callback is a grammar setting using the ::default meta rule, e.g.:
::default
:default ::= regex-action => do_regexCallout
where the callback, do_regexCallout here, must reside in the recognizer interface. Callouts are writen as per PCRE2 syntax, e.g.:
do_regexCallout
someRule ::= /[\d]+(?C"CallbackIdentifier as a string")/ someRule ::= /X(?C123)/
The callout function is interpreted as an integer, whose value conforms to PCRE2 specification at https://www.pcre.org/current/doc/html/pcre2callout.html:
ESLIF prevents negative values to be lower than the most negative meaningful value. Exhaustive current list is as of PCRE2 version 10.33, i.e.:
Any value lower than PCRE2_ERROR_INTERNAL_DUPMATCH will emit a warning by ESLIF, the later changing it to PCRE2_ERROR_CALLOUT.
PCRE2_ERROR_INTERNAL_DUPMATCH
PCRE2_ERROR_CALLOUT
Returns callout number or undef
Returns callout string or undef
Returns current subject
Returns pattern
Returns the max recent capture
Returns the most recently closed capture
Returns a reference to an array containing offsets
Returns the most recently passed NAME of a (*MARK:NAME), (*PRUNE:NAME) or (*THEN:NAME) item in the match, undef if none.
NAME
(*MARK:NAME)
(*PRUNE:NAME)
(*THEN:NAME)
Returns the current mark start attempt offset
Returns the current subject offset
Returns the next item in the pattern
PCRE2 Callout Specification
Jean-Damien Durand <jeandamiendurand@free.fr>
This software is copyright (c) 2017 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.
To install MarpaX::ESLIF, copy and paste the appropriate command in to your terminal.
cpanm
cpanm MarpaX::ESLIF
CPAN shell
perl -MCPAN -e shell install MarpaX::ESLIF
For more information on module installation, please visit the detailed CPAN module installation guide.