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

BUG: should match: grammar A { rule TOP { ^ } }; say A.parse(' ') #2640

Closed
p6rt opened this issue Feb 5, 2012 · 6 comments
Closed

BUG: should match: grammar A { rule TOP { ^ } }; say A.parse(' ') #2640

p6rt opened this issue Feb 5, 2012 · 6 comments

Comments

@p6rt
Copy link

p6rt commented Feb 5, 2012

Migrated from rt.perl.org#109874 (status was 'resolved')

Searchable as RT109874$

@p6rt
Copy link
Author

p6rt commented Feb 5, 2012

From @cognominal

grammar A { rule TOP { ^  } }; say A.parse(' ')
#<failed match>

The relevant spec is probably S05​:355

When you write

  rule TOP { ^ <stuff> $ }

this is the same as

  token TOP { ^ <.ws> <stuff> <.ws> $ <.ws> }

discussed with jonathan at http://irclog.perlgeek.de/perl6/2012-02-05#i_5106223

A test should probably added spec/S05-grammar/ws.t :

grammar A { rule TOP { ^ } };
ok ?A.parse(' '), 'no <.ws> shoved before ^';

--
cognominal stef

@p6rt
Copy link
Author

p6rt commented Jun 24, 2012

From sirrobert@gmail.com

Bug report. The snippet below (and associated github gist) says it all.

-Sir

20​:07 < sirrobert> I'm learning to write grammars, but having a wierd
problem. (I think there's something I don't get about newlines or
something).
20​:07 < sirrobert> https://gist.github.com/2980628
20​:08 < pmichaud> \s* doesn't really make sense in a rule
20​:08 < sirrobert> ok...
20​:08 < pmichaud> since whitespaces in the rule already implies \s*
20​:08 < sirrobert> I can't get it to ignore the first part of a slurped file
20​:08 < pmichaud> inside of method verb($/), you might want 'eq' instead of
'=='
20​:09 < sirrobert> oh, yeah
20​:10 < sirrobert> Still, adding a blank line at the top of the file breaks
it
20​:10 < sirrobert> even with the \s* removed
20​:10 < pmichaud> looking
20​:11 < sirrobert> (cleaned up the gist by replacing == with 'eq' and
removed the \s* in all places. Same problem)
20​:13 < pmichaud> ah, it's the ^ that's an issue.
20​:14 < pmichaud> it's somewhat of a rakudobug; the whitespace before the ^
is eating up the newline before testing for "start of string", and with
'rule' there's no backtracking.
20​:14 < sirrobert> ok!
20​:14 < pmichaud> I think a recentish spec change causes leading whitespace
before a ^ to be ignored... but rakudo doesn't implement that.
20​:14 < sirrobert> glad it's not me =)
20​:14 < pmichaud> so, eliminate the space before the ^ and maybe it will
work.
20​:14 < pmichaud> or, switch TOP to be a 'token' instead of a 'rule'
20​:15 < sirrobert> ok, great.

@p6rt
Copy link
Author

p6rt commented Jul 28, 2013

From @masak

<masak> r​: grammar G { token TOP { ^<foo>$ }; rule foo { foo } }; say ?
G.parse(" foo")
<camelia> rakudo 96776b​: OUTPUT«True␤»
<masak> r​: grammar G { token TOP { ^<foo>$ }; rule foo {foo } }; say ?
G.parse(" foo")
<camelia> rakudo 96776b​: OUTPUT«False␤»
<masak> I thought rules ignored initial whitespace...
<moritz> masak​: it's fascinating how rakudo still parses so well, being
built on Perl 6 rules... :-)
<masak> heh.
* masak does a search through RT first
<masak> here is some discussion in a rejected ticket​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=75668
<masak> ah -- here​: https://rt-archive.perl.org/perl6/Ticket/Display.html?
id=109874
<masak> let's just add today's discussion to that one.

@p6rt
Copy link
Author

p6rt commented Jul 28, 2013

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

@p6rt
Copy link
Author

p6rt commented Apr 14, 2014

From @Mouq

On Sun Jul 28 10​:05​:00 2013, masak wrote​:

<masak> r​: grammar G { token TOP { ^<foo>$ }; rule foo { foo } }; say ?
G.parse(" foo")
<camelia> rakudo 96776b​: OUTPUT«True␤»
<masak> r​: grammar G { token TOP { ^<foo>$ }; rule foo {foo } }; say ?
G.parse(" foo")
<camelia> rakudo 96776b​: OUTPUT«False␤»
<masak> I thought rules ignored initial whitespace...
<moritz> masak​: it's fascinating how rakudo still parses so well, being
built on Perl 6 rules... :-)
<masak> heh.
* masak does a search through RT first
<masak> here is some discussion in a rejected ticket​:
https://rt-archive.perl.org/perl6/Ticket/Display.html?id=75668
<masak> ah -- here​: https://rt-archive.perl.org/perl6/Ticket/Display.html?
id=109874
<masak> let's just add today's discussion to that one.

This significant whitespace has worked correctly for about half a year now in Rakudo. Additionally​:

$ perl6 -e'grammar G { token TOP { ^<foo>$ }; rule foo { foo } }; say ?G.parse(" foo")'
False
$ perl6 -e'grammar G { token TOP { ^<foo>$ }; rule foo { foo } }; say ?G.parse("foo")'
True
$ perl6 -e'grammar G { rule TOP { ^ <foo> $ }; rule foo { foo } }; say ?G.parse(" foo")'
True

These are the correct semantics. Marking this as resolved

@p6rt
Copy link
Author

p6rt commented Apr 14, 2014

@Mouq - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Apr 14, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant