Skip Menu |
Report information
Id: 132003
Status: open
Priority: 0/
Queue: perl6

Owner: Nobody
Requestors: daxim <daxim [at]>

Severity: (no value)
Tag: (no value)
Platform: (no value)
Patch Status: (no value)
VM: (no value)

Subject: grammar cannot parse from Blob/Buf
Download (untitled) / with headers
text/plain 739b
› perl6 -v This is Rakudo version 2017.07 built on MoarVM version 2017.07 implementing Perl 6.c. › cat 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([50,32,43,32,51])); # '2 + 3' › perl6 「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 line 9 It appears grammars only accept strings, but I also want to parse non-text input, e.g. binary file formats.
Download (untitled) / with headers
text/plain 510b
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. Marking this ticket [NYI]. --- 1) 2)

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at