Hi there,
I'm tryin to parse this file:
Model= 9: ParaLinux (Production)
:KMW
MajorVersion=1
MinorVersion=5
Path=farmas
:eKMW
With this :
#!/usr/bin/perl
use strict; use warnings; #use 5.010;
use Data::Dumper;
use File::Slurp;
my $filename = $ARGV[0];
my $data = read_file($filename);
$data =~ s/\r//g;
#print "$data";
my $ast = Parser->parse(\$data);
print Dumper $ast;
# Below is a class that wraps the Marpa Parser
package Parser;
use Marpa::R2;
my ($grammar);
sub parse {
my ($self, $ref) = @_;
my $recce = Marpa::R2::Scanless::R->new({ grammar => $grammar });
$recce->read($ref);
my $val = $recce->value;# // die "No parse found"; <<<<<<<<<<<<<<< errors here with this message :
#################### Can't use an undefined value as a SCALAR reference at files/
gistfile2.pl line 25.
return $$val;
}
BEGIN {
$grammar = Marpa::R2::Scanless::G->new({
bless_package => 'Ast',
source => \<<'END SOURCE',
:default ::= action => [name,values]
lexeme default = action => [ start, length, value ] bless => ::name latm => 1
:start ::= KBxpw
KBxpw ::= KBxpwHEAD KBxpwTAIL bless => KBxpw
KBxpwHEAD ::= ModelName1 EcolonBlock bless => KBxpwHEAD
ModelName1 ::= ('Model=') ModelName bless => ModelName1
KBxpwTAIL ::= EcolonBlock bless => KBxpwTAIL
ModelName ~ [0-9: A-Za-z\(\)]+
KBxpwHEAD ::= EcolonBlock bless => KBxpwHEAD
EcolonBlock ::= BeginMark Body EndMark bless => EcolonBlock
BeginMark ::= colon blockname bless => BeginMark
EndMark ::= colonend blockname bless => EndMark
Body ::= Lines
Lines ::= Line*
Line ~ [\=\^\<\>\|\ \_\-\,\;\:\!\?\/\.\'\"\(\)\[\]\{\}\@\$\*\\\&\#\%\+\.0-9a-zA-Z]*
#Line ~ [\^\<\>\|\ \_\-\,\;\:\!\?\/\.\'\"\(\)\[\]\{\}\@\$\*\\\&\#\%\+\.0-9a-zA-Z]*
blockname ~ [A-Za-z]+
colon ~ [:]
colonend ~ ':e'
ws ~ [\s]+
:discard ~ ws
END SOURCE
});
}
------------
If I use the second "Line" L0 definition, I get this error:
[haroldo@semiosis ~]$ files/
gistfile2.pl files/KBheader.xpw
Error in SLIF parse: No lexeme found at line 3, column 15
* String before error: = 9: ParaLinux (Production)\n:KMW\n MajorVersion
* The error was at line 3, column 15, and at character 0x003d '=', ...
* here: =1\n MinorVersion=5\n Path=farmas\n:eKMW\n
Marpa::R2 exception at files/
gistfile2.pl line 23.
which makes me think there is some oddity related to non-letters , but I don't know.
Any hint is really welcome !
h