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
'#' literals in Grammars: syntax error #1324
Comments
Reported as rakudo/rakudo#1324
Not sure whether this is a bug or a feature, but there *is* a workaround:
regex TOP { '#' <stuff> }
… On 20 Dec 2017, at 07:37, Juan Julián Merelo Guervós ***@***.***> wrote:
The Problem
There does not seem to be a way of including hashes (#) in grammars except by including the using `\c'
Expected Behavior
Pretty much as it works in regular expressions, Escaping it should work, like here
> '#' ~~ /\#/
「#」
Actual Behavior
grammar Fails {
regex TOP { \# <stuff> }
token stuff { \w+ }
}
my $parsed = Fails.parse( "#stuff");
Fails with:
$ perl6 Fails.p6
===SORRY!===
Missing required term after infix
at /home/jmerelo/Code/perl6/dev.to-code/perl6/Fails.p6:3
------> token stuff { \w+ ⏏}
expecting any of:
prefix
term
Other potential difficulties:
Space is not significant here; please use quotes or :s (:sigspace) modifier (or, to suppress this warning, omit the space, or otherwise change the spacing)
at /home/jmerelo/Code/perl6/dev.to-code/perl6/Fails.p6:3
------> token⏏ stuff { \w+ }
Steps to Reproduce
Save the code above and run with perl6 fails.p6. It does not matter if it's a token either.
Environment
• Operating system: Ubuntu
• Compiler version (perl6 -v):
This is Rakudo version 2017.11 built on MoarVM version 2017.11
implementing Perl 6.c.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
2017-12-20 12:44 GMT+01:00 lizmat <notifications@github.com>:
Not sure whether this is a bug or a feature, but there *is* a workaround:
regex TOP { '#' <stuff> }
Thanks!
|
Reading the core code, looks like the reason In fact, if you wiggle it just a little, the
The same pattern appears to apply to tokens too: if there's no whitespace before the
Unsure of exact rules of unspaces, but seems like this is working as expected, even if surprising. |
💯
Whatever the course you decide it to be, my opinion is that it would be
best if they behaved in the same way.
|
Some comments: https://irclog.perlgeek.de/perl6-dev/2017-12-21#i_15606474
https://irclog.perlgeek.de/perl6-dev/2017-12-21#i_15609321
|
Thanks for the update!
|
Ping |
I'd say it is clear from the conversation that this is a case of wontfix / not-a-bug ticket, so should be closed. |
Hi! Even if it's OK for this to yield a syntax error, I'd like people to elaborate on the fact that it works in some cases:
As I see it, it should be all or nothing. S02, although possibly obsolete, had this to say:
The current test is a bit too concise but seems to proceed in the same spirit:
Would you consider re-opening this bug? |
To be honest it is painful to see people spending efforts on something so tiny from a wider programming perspective that most would not really notice the issue, do the |
I feel your pain. I hit a problem and looked around, to the point of opening a documentation issue after reading this very thread. It turned out that the real intention was originally in agreement with the docs, so there's understandable resistance to change them. I'm fine with either a change in the code or a change in the spec/tests/docs, whatever is deemed "better" -- including the wider programming perspective. This requires a design decision though. Do you think that it would be better to open an Issue in the Roast repository, adding more tests to better "spec" this behavior? In the meantime, other people are likely to trip over this 🤷 |
Sorry to cause you pain 😁 But, imo, "make it → make it right → make it fast" is a good progression to stick to, and we're mostly on the "make it fast" part for Raku – which makes fixing the few remaining correctness bugs worthwhile. Plus, I really like that Raku usually doesn't make me remember inconsistancies like "you can escape non-alphanumeric characters with But in any event, I have a fix now, so I don't think any of us will need to spend much more time figuring this out :) |
The Problem
There does not seem to be a way of including hashes (
#
) in grammars except by using `\c'Expected Behavior
Pretty much as it works in regular expressions, Escaping it should work, like here
Actual Behavior
Fails with:
Steps to Reproduce
Save the code above and run with perl6 fails.p6. It does not matter if it's a token either.
Environment
perl6 -v
):The text was updated successfully, but these errors were encountered: