#!perl
use strict;
use warnings;
use Data::Dumper qw/Dumper/;
use Marpa::R2;
use String::Random;
$Data::Dumper::Deepcopy = 1;
my $dsl = <<'END_OF_DSL';
:default ::= action => [name,values]
lexeme default = latm => 1
Expression ::=
Expression '=' Expression
| QuotedWord
| Word
QuotedWord ::= '"' Word '"'
Word ~ charsnwhite
charsnwhite ~ [\w]+
:discard ~ whitespace
whitespace ~ [\s]+
END_OF_DSL
my $grammar = Marpa::R2::Scanless::G->new( { source => \$dsl } );
my $input = String::Random->new->randregex('\w{5,8}\s=\s\w{6,9}');
print "Input = $input\n";
my $value_ref = $grammar->parse( \$input, 'My_Actions' );
print Dumper $value_ref;
$VAR1 = \[
'Expression',
[
'Expression',
'AhwGH'
],
'=',
[
'Expression',
'SEognP8P'
]
];
On Mon, Oct 20, 2014 at 6:13 PM, <[email protected]> wrote:
> Hi!
>
> I'm sorry, this is not what I was looking for. My description lacked this
> specific point - sorry.
> These multi words can be arbitrary text even without any white space at
> all. Thus, matching the string "multi word" followed by a or b will not
> work.
>
> I updated the example code to show it more clrealy, with the use of
> String::Random:
>
> #!perl
>
> use strict;
> use warnings;
> use Data::Dumper qw/Dumper/;
> use Marpa::R2;
> use String::Random;
>
> $Data::Dumper::Deepcopy = 1;
>
> my $dsl = <<'END_OF_DSL';
> :default ::= action => [name,values]
> lexeme default = latm => 1
>
> Expression ::=
> Expression '=' Expression
> | QuotedWord
> | Word
>
> QuotedWord ::= '"' Word '"'
>
> Word ~ charsnwhite
> charsnwhite ~ [\w]+
> :discard ~ whitespace
> whitespace ~ [\s]+
> END_OF_DSL
>
>
> my $grammar = Marpa::R2::Scanless::G->new( { source => \$dsl } );
>
> my $input = String::Random->new->randregex('\w{5,8}\s\w{6,9}');
> print "Input = $input\n";
>
> my $value_ref = $grammar->parse( \$input, 'My_Actions' );
> print Dumper $value_ref;
>
>
>
> Am Montag, 20. Oktober 2014 16:14:53 UTC+2 schrieb [email protected]:
>
>> Hi!
>>
>> I just tried to parse tokens containing white spaces. They are surrounded
>> by double quotes. Perspectively, escaped quotes inside the token should be
>> possible.
>>
>> I hoped there would be an easier way than a 2 pages grammar for "only"
>> parsing tokens containing white spaces (like the one mentioned here:
>> https://groups.google.com/forum/?fromgroups#!topic/
>> marpa-parser/kthX_WUfE_o ).
>>
>> Here is an example program of what I tried:
>>
>> #!perl
>>
>> use strict;
>> use warnings;
>> use Data::Dumper qw/Dumper/;
>> use Marpa::R2;
>>
>> $Data::Dumper::Deepcopy = 1;
>>
>> my $dsl = <<'END_OF_DSL';
>> :default ::= action => [name,values]
>> lexeme default = latm => 1
>>
>> Expression ::=
>> Expression '=' Expression
>> | QuotedWord
>> | Word
>>
>> QuotedWord ::= '"' Word '"'
>>
>> Word ~ charsnwhite
>> charsnwhite ~ [multi wordab]+
>> :discard ~ whitespace
>> whitespace ~ [\s]+
>> END_OF_DSL
>>
>>
>> my $grammar = Marpa::R2::Scanless::G->new( { source => \$dsl } );
>>
>> #my $input = '"multi word"';
>> my $input = '"multi word a" = "multi word b"';
>>
>> my $value_ref = $grammar->parse( \$input, 'My_Actions' );
>> print Dumper $value_ref;
>>
>> The input may be "multi word" which should be considered as one token.
>> The goal is to get the stuff at the left side and at the right side of the
>> equals sign to be able to compare it. (I beg you, please don't ask why).
>>
>> So, is there a simple way to get '"multi word a" = "multi word b"' into
>> something like this?
>>
>>
>> $VAR1 = \[
>>> 'Expression',
>>> [
>>> 'multi word a',
>>> '='
>>> 'multi word b',
>>> ]
>>> ];
>>>
>>
>> Best regards,
>> Alex
>>
> --
> You received this message because you are subscribed to the Google Groups
> "marpa parser" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"marpa parser" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.