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

whitespace before ^ in rule #1814

Closed
p6rt opened this issue Jun 11, 2010 · 8 comments
Closed

whitespace before ^ in rule #1814

p6rt opened this issue Jun 11, 2010 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 11, 2010

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

Searchable as RT75668$

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

From rirans@comcast.net

In
commit a5467733bdab87210a4eae6d3af309a0c3041c87
I think it is a bug that these differ

rule TOP { ^ <tok> }
rule TOP {^ <tok> }

If I'm far from right, let me know so I
won't waste folks time.

Thank you for rakudo.

Be well,
rir

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

From rirans@comcast.net

use Test;

grammar A {
  rule TOP {^ <a> $}
  token a { 'a' }
}

grammar B {
  rule TOP { ^ <a> $ }
  token a { 'a' }
}
my @​t = (
  'a',
  ' a',
  'a ',
);

for @​t -> $t {
  ok (A.parse($t) and B.parse( $t) ), qq{whitespace before ^, aft \$} ;
}

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

From @moritz

On Thu Jun 10 21​:11​:42 2010, rirans@​comcast.net wrote​:

In
commit a5467733bdab87210a4eae6d3af309a0c3041c87
I think it is a bug that these differ

rule TOP { ^ <tok> }
rule TOP {^ <tok> }

It actually conforms the current spec. Each consecutive run of
whitespace is replaced by a call to <.ws>. So the first rule is
equivalent to

token TOP { <.ws> ^ <.ws> <tok> <.ws> }

When there is leading whitespace in the string, the first <.ws> matches,
and ^ fails. Since there's no backtracking in a token, the match fails.

I agree that that it's not obvious or intuitive, but rakudo should only
special-case it if the spec says so.

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

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

@p6rt
Copy link
Author

p6rt commented Jun 11, 2010

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

@p6rt p6rt closed this as completed Jun 11, 2010
@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From rirans@comcast.net

On Fri, Jun 11, 2010 at 02​:16​:28PM -0700, Moritz Lenz via RT wrote​:

On Thu Jun 10 21​:11​:42 2010, rirans@​comcast.net wrote​:

I think it is a bug that these differ

rule TOP { ^ <tok> }
rule TOP {^ <tok> }

It actually conforms the current spec. Each consecutive run of
whitespace is replaced by a call to <.ws>. So the first rule is
equivalent to

token TOP { <.ws> ^ <.ws> <tok> <.ws> }

When there is leading whitespace in the string, the first <.ws> matches,
and ^ fails. Since there's no backtracking in a token, the match fails.

I agree that that it's not obvious or intuitive, but rakudo should only
special-case it if the spec says so.

Thanks for the reply, I'll be slower to submit bugs.

I get your point. I think the spec may be open to other interpretations
though​:

  ^ and $ now always match the start/end of a string,

How can even a zero-width atom ever match before the start of a string?
What are we matching against?

I think whitespace before a leading/trailing ^/$ needs to be discounted.
Dwimmery and elegance demand.

It is foul if the "formalization" of matching leads us to

rule TOP {
  : my $dog = "Magic";
  ^ <matchme>
}

needing to be

rule TOP {
  : my $dog = "Magic";^
  <matchme>
}

Either way, the spec needs to be clarified.

Moritz, I appreciate the time you have taken with me. I'm more or less
at 5.005 regarding regexes, so some of the Perl5 refs in the synopses are
not so helpful to me. I'm am excited by grammars; they change
the mentation of matching.

On Perlmonks, I have found your answers satisfying but was disappointed
that we seem to be a party of two (at least there is an audience). I feel
that I could wear you out with my questions. I like Perlmonks, but could
move to another site.

Be well,
rir

@p6rt
Copy link
Author

p6rt commented Jun 12, 2010

From not.com@gmail.com

...
On Perlmonks, I have found your answers satisfying but was disappointed
that we seem to be a party of two (at least there is an audience).  I feel
that I could wear you out with my questions.  I like Perlmonks, but could
move to another site.

A good thing about perlmonks is that your audience is likely to grow,
and those posts will be referenced by future perl6-ers.

@p6rt
Copy link
Author

p6rt commented Jun 14, 2010

From bruce@drangle.com

I think whitespace before a leading/trailing ^/$ needs to be discounted.
Dwimmery and elegance demand.

+1

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

No branches or pull requests

1 participant