Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

Grammars parsing from Blob/Buf #6483

Open p6rt opened 6 years ago

p6rt commented 6 years ago

Migrated from rt.perl.org#132003 (status was 'open')

Searchable as RT132003$

p6rt commented 6 years ago

From @daxim

  › 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 { [ \ | \ ] }   rule add { \ '+' \ }   rule sub { \ '-' \ }   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 \ 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.

p6rt commented 6 years ago

From @smls

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) https://docs.perl6.org/routine/decode 2) http://design.perl6.org/S05.html#line_476

p6rt commented 6 years ago

The RT System itself - Status changed from 'new' to 'open'