You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
� perl6 -v
This is Rakudo version 2017.07 built on MoarVM version 2017.07
implementing Perl 6.c.
� cat calc.pl
use v6;
grammar Calculator {
token TOP { [ <add> | <sub> ] }
rule add { <num> '+' <num> }
rule sub { <num> '-' <num> }
token num { \d+ }
}
say Calculator.parse('2 + 3');
say Calculator.parse(Blob.new([50,32,43,32,51])); # '2 + 3'
� perl6 calc.pl
ï½¢2 + 3ï½£
add => ï½¢2 + 3ï½£
num => ï½¢2ï½£
num => ï½¢3ï½£
Cannot use a Buf as a string, but you called the Str method on it
in block <unit> at calc.pl line 9
It appears grammars only accept strings, but I also want to parse
non-text input, e.g. binary file formats.
In Perl 6.c, regexes/grammars can only parse strings (at the grapheme level).
If you want to parse a Blob or Buf, you have to decode it into a string first by calling the `.decode` method¹ on it.
Early Perl 6 design documents² suggested support for parsing at the byte or code-point level, but this hasn't become part of the language yet.
I suspect it might be added in a future version.
Migrated from rt.perl.org#132003 (status was 'open')
Searchable as RT132003$
The text was updated successfully, but these errors were encountered: