Created
December 20, 2013 05:55
-
-
Save jddurand/8050950 to your computer and use it in GitHub Desktop.
Marpa literal() and UTF8 flag
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!env perl | |
use strict; | |
use diagnostics; | |
use Marpa::R2; | |
use Devel::Peek; | |
my $grammar_source = do {local $/; <DATA>}; | |
my $input = "\x{2665}"; | |
print "INPUT:\n--------------------\n"; | |
Dump($input); | |
my $grammar = Marpa::R2::Scanless::G->new({ source => \$grammar_source}); | |
my $re = Marpa::R2::Scanless::R->new( { grammar => $grammar } ); | |
$re->read(\$input); | |
my ($start, $length) = $re->g1_location_to_span($re->current_g1_location()); | |
my $char = $re->literal($start, $length); | |
print "recce->literal\n--------------------\n"; | |
Dump($char); | |
print "recce->range_to_string\n--------------------\n"; | |
my $test = $re->range_to_string($re->last_completed_range('test')); | |
Dump($test); | |
__DATA__ | |
:start ::= test | |
test ::= char | |
char ~ [\x{2665}] | |
:lexeme ~ <char> pause => after event => 'char' |
That was definitely a bug and may well explain all the other issues. I think I've found the fix. Here's the output from my latest developer's version.
INPUT:
--------------------
SV = PV(0xa094c00) at 0xa1c6a10
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0x9fe4de0 "\342\231\245"\0 [UTF8 "\x{2665}"]
CUR = 3
LEN = 4
recce->literal
--------------------
SV = PV(0xa6622b8) at 0xa0022e0
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0xa558fe8 "\342\231\245"\0 [UTF8 "\x{2665}"]
CUR = 3
LEN = 4
recce->range_to_string
--------------------
SV = PV(0xa6622d8) at 0xa1d8190
REFCNT = 1
FLAGS = (PADMY,POK,pPOK,UTF8)
PV = 0xa6553b0 "\342\231\245"\0 [UTF8 "\x{2665}"]
CUR = 3
LEN = 4
Thanks!
I suppose a test suite checking the flag using is_utf8() could be added.
Thanks / JD.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: