#!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 word ' [ab]
: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;
$VAR1 = \[
'Expression',
[
'Expression',
[
'QuotedWord',
'multi word a'
]
],
'=',
[
'Expression',
[
'QuotedWord',
'multi word b'
]
]
];
On Mon, Oct 20, 2014 at 5:14 PM, <[email protected]> wrote:
> 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.