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

Grammar.parse doesn't anchor to the end of the parsed string #2020

Closed
p6rt opened this issue Aug 5, 2010 · 4 comments
Closed

Grammar.parse doesn't anchor to the end of the parsed string #2020

p6rt opened this issue Aug 5, 2010 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Aug 5, 2010

Migrated from rt.perl.org#77022 (status was 'rejected')

Searchable as RT77022$

@p6rt
Copy link
Author

p6rt commented Aug 5, 2010

From ekiru.0@gmail.com

[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('abc').Bool; # this is right
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«0␤»
[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('bc').Bool; # I don't think this is.
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«1␤»
[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('ab').Bool; # Also right.
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«0␤»
[1​:39pm] tylercurtis​: Grammar.parse seems to anchor to the beginning
of the string but not to the end.

If I correctly understand the behavior of Grammar.parse and regex
methods, only "b" should match the Foo grammar above because regex
methods are automatically anchored to the beginning and end of the
string when called directly as Grammar.parse should do with Foo.TOP.

--
Tyler Curtis

@p6rt
Copy link
Author

p6rt commented Aug 8, 2010

From @masak

ekiru (>)​:

[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('abc').Bool; # this is right
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«0␤»
[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('bc').Bool; # I don't think this is.
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«1␤»
[1​:38pm] tylercurtis​: rakudo​: grammar Foo { token TOP { 'b' } }; say
Foo.parse('ab').Bool; # Also right.
[1​:38pm] p6eval​: rakudo 19931f​: OUTPUT«0␤»
[1​:39pm] tylercurtis​: Grammar.parse seems to anchor to the beginning
of the string but not to the end.

If I correctly understand the behavior of Grammar.parse and regex
methods, only "b" should match the Foo grammar above because regex
methods are automatically anchored to the beginning and end of the
string when called directly as Grammar.parse should do with Foo.TOP.

I went looking for support of this view in S05. Didn't find any.

The reason the 'b' is only matched at the beginning of the string in the examples above has
nothing to do with the grammar anchoring to the beginning of the string, but is a consequence
of the 'token' keyword turning backtracking off, and starting the match at a new position counts
as a form of backtracking.

Rejecting the ticket.

@p6rt
Copy link
Author

p6rt commented Aug 8, 2010

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

@p6rt
Copy link
Author

p6rt commented Aug 8, 2010

@masak - Status changed from 'open' to 'rejected'

@p6rt p6rt closed this as completed Aug 8, 2010
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