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

rule's capture ws #478

Closed
p6rt opened this issue Dec 12, 2008 · 11 comments
Closed

rule's capture ws #478

p6rt opened this issue Dec 12, 2008 · 11 comments

Comments

@p6rt
Copy link

p6rt commented Dec 12, 2008

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

Searchable as RT61308$

@p6rt
Copy link
Author

p6rt commented Dec 12, 2008

From martin@martinkjeldsen.dk

When using rules at least with <ws> overwritten, the rule also captures
whitespace. Please see attached file for example.

It is tested with revision 33823.

Martin

@p6rt
Copy link
Author

p6rt commented Dec 12, 2008

From martin@martinkjeldsen.dk

grammar NG {
  rule TOP { ^ <line>+ $ };

  #whitespace rules is borrowed from pipp
  # Whitespace and comments
  token ws_char { \h | \v }

  token singlelinecomment { [ '#' || '//' ] \N* } # end of line comment like Unix shell and C++

  token multilinecomment { '/*' .*? '*/' } # C-like multiline comment

  token ws_all {
  <.ws_char>
  | <.singlelinecomment>
  | <.multilinecomment>
  }

  token ws {
  <.ws_all>*
  }

  rule line {
  'default' \w+
  }
};

my $str = 'default testtesttest
// this is a comment shouldn\'t be outputted';

$str ~~ NG;

die("No match") unless ~$/;

say $/<line>[0];

@p6rt
Copy link
Author

p6rt commented Dec 14, 2008

From @moritz

Martin Kjeldsen (via RT) wrote​:

# New Ticket Created by Martin Kjeldsen
# Please include the string​: [perl #​61308]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=61308 >

When using rules at least with <ws> overwritten, the rule also captures
whitespace. Please see attached file for example.

You're right that there's a bug, but the real issue is that 'token ws {
... }' isn't used by implicit <.ws> in rules yet​:

grammar A {
  token ws { 'a' };
  rule b {x y};
};

if 'xab' ~~ m/ ^ <A​::b> $/ {
  say "match";
} else {
  say "no match";
}
# output​: no match\n

Thank you for your report,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 14, 2008

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

@p6rt
Copy link
Author

p6rt commented Dec 14, 2008

From @chrisdolan

On Dec 13, 2008, at 3​:44 AM, Moritz Lenz wrote​:

Martin Kjeldsen (via RT) wrote​:

# New Ticket Created by Martin Kjeldsen
# Please include the string​: [perl #​61308]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=61308 >

When using rules at least with <ws> overwritten, the rule also
captures
whitespace. Please see attached file for example.

You're right that there's a bug, but the real issue is that 'token
ws {
... }' isn't used by implicit <.ws> in rules yet​:

grammar A {
token ws { 'a' };
rule b {x y};
};

if 'xab' ~~ m/ ^ <A​::b> $/ {
say "match";
} else {
say "no match";
}
# output​: no match\n

Thank you for your report,
Moritz

In which case, the root cause may be the same as
  [perl #​57864] Calling a token "text", "null" or "ws" in Rakudo
makes matching fail

Chris

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

From @moritz

Moritz Lenz wrote​:

Martin Kjeldsen (via RT) wrote​:

# New Ticket Created by Martin Kjeldsen
# Please include the string​: [perl #​61308]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=61308 >

When using rules at least with <ws> overwritten, the rule also captures
whitespace. Please see attached file for example.

You're right that there's a bug, but the real issue is that 'token ws {
... }' isn't used by implicit <.ws> in rules yet​:

grammar A {
token ws { 'a' };
rule b {x y};
};

if 'xab' ~~ m/ ^ <A​::b> $/ {
say "match";
} else {
say "no match";
}
# output​: no match\n

The output is still "no match" for me, but the tests I've added to
t/spec/S05-grammar/ws.t all pass, and they seem to test for exactly the
same thing. Or maybe I'm too tired to figure it out right now... any ideas?

Cheers,
Moritz

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

From martin@martinkjeldsen.dk

Moritz Lenz via RT (09​:23 2008-12-14)​:

Martin Kjeldsen (via RT) wrote​:

# New Ticket Created by Martin Kjeldsen
# Please include the string​: [perl #​61308]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=61308 >

When using rules at least with <ws> overwritten, the rule also captures
whitespace. Please see attached file for example.

You're right that there's a bug, but the real issue is that 'token ws {
... }' isn't used by implicit <.ws> in rules yet​:

grammar A {
token ws { 'a' };
rule b {x y};
};

if 'xab' ~~ m/ ^ <A​::b> $/ {
say "match";
} else {
say "no match";
}
# output​: no match\n

Thank you for your report,
Moritz

Hi Moritz,

you're right, I can't get your example to work. But I think you meant

if 'xay' ~~ m/ ^ <A​::b> $/ { # y instead of b in string

and shouldn't it be rule b {'x' 'y'}; or doesn't that matter (I don't know).

But no matter it still doesn't work for some reason.

But more importantly if the whole problem is the <ws> is not overwritten I don't
understand why my example matches, but doesn't match if I remove the <ws> token.
Surely <ws> shouldn't default match C style comments.

Martin

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

From @pmichaud

On Mon Dec 15 03​:43​:26 2008, baest wrote​:

Moritz Lenz via RT (09​:23 2008-12-14)​:

Martin Kjeldsen (via RT) wrote​:

# New Ticket Created by Martin Kjeldsen
# Please include the string​: [perl #​61308]
# in the subject line of all future correspondence about this
issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=61308 >

When using rules at least with <ws> overwritten, the rule also
captures
whitespace. Please see attached file for example.

You're right that there's a bug, but the real issue is that 'token
ws {
... }' isn't used by implicit <.ws> in rules yet​:

grammar A {
token ws { 'a' };
rule b {x y};
};

if 'xab' ~~ m/ ^ <A​::b> $/ {
say "match";
} else {
say "no match";
}
# output​: no match\n

Thank you for your report,
Moritz

Hi Moritz,

you're right, I can't get your example to work. But I think you meant

if 'xay' ~~ m/ ^ <A​::b> $/ { # y instead of b in string

and shouldn't it be rule b {'x' 'y'}; or doesn't that matter (I don't
know).

But no matter it still doesn't work for some reason.

The following version works fine for me​:

$ cat x
grammar A {
  token ws { 'a' };
  rule b {x y};
};

if 'xay' ~~ m/^ <A​::b> $/ { say 'match'; }
else { say 'nomatch'; }

$ ./parrot perl6.pbc x
match
$

So, clearly the <ws> rule is being called.

See next reply for the other example.

Pm

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

From @pmichaud

On Fri Dec 12 04​:52​:12 2008, baest wrote​:

When using rules at least with <ws> overwritten, the rule also captures
whitespace. Please see attached file for example.

The problem is with trying to invoke the rule using "$str ~~ NG​::TOP" --
that's not a valid syntax for invoking a rule in a grammar.

Using "$str ~~ /<NG​::TOP>/" instead gets the correct match -- see
attached example.

Marking ticket as resolved, thanks!

Pm

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

From @pmichaud

$ cat NG.pl
grammar NG {
  rule TOP { ^ <line>+ $ };

  #whitespace rules is borrowed from pipp
  # Whitespace and comments
  token ws_char { \h | \v }

  # end of line comment like Unix shell and C++
  token singlelinecomment { [ '#' || '//' ] \N* }

  # C-like multiline comment
  token multilinecomment { '/*' .*? '*/' }

  token ws_all {
  <.ws_char>
  | <.singlelinecomment>
  | <.multilinecomment>
  }

  token ws { <.ws_all>* }

  rule line {
  'default' \w+
  }
};

my $str = 'default testtesttest
// this is a comment shouldn\'t be outputted';

$str ~~ /<NG​::TOP>/;

die("No match") unless ~$/;

say $<NG​::TOP><line>[0];

$ ./parrot perl6.pbc NG.pl
default testtesttest
// this is a comment shouldn't be outputted

@p6rt
Copy link
Author

p6rt commented Dec 15, 2008

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

@p6rt p6rt closed this as completed Dec 15, 2008
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