Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Grammars parsing from Blob/Buf #6483

Open
p6rt opened this issue Aug 31, 2017 · 3 comments
Open

Grammars parsing from Blob/Buf #6483

p6rt opened this issue Aug 31, 2017 · 3 comments
Labels
NYI Features not yet implemented

Comments

@p6rt
Copy link

p6rt commented Aug 31, 2017

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

Searchable as RT132003$

@p6rt
Copy link
Author

p6rt commented Aug 31, 2017

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 { [ <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.

@p6rt
Copy link
Author

p6rt commented Aug 31, 2017

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
Copy link
Author

p6rt commented Aug 31, 2017

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

@p6rt p6rt added the NYI Features not yet implemented label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NYI Features not yet implemented
Projects
None yet
Development

No branches or pull requests

1 participant