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

proto+multi regex rules [NYI] #4311

Open
p6rt opened this issue Jun 10, 2015 · 1 comment
Open

proto+multi regex rules [NYI] #4311

p6rt opened this issue Jun 10, 2015 · 1 comment

Comments

@p6rt
Copy link

@p6rt p6rt commented Jun 10, 2015

Migrated from rt.perl.org#125374 (status was 'new')

Searchable as RT125374$

@p6rt

This comment has been minimized.

Copy link
Author

@p6rt p6rt commented Jun 10, 2015

From @skids

# I believe this is a known NYI but it is probably about time there was
# an RT for it.

# Rakudo's proto+multi grammar rules don't function as specced. They
# should be equivalent to an '|' alternative.

# These two grammars should produce identical results
grammar g1 {
proto token m {*}
multi token m​:sep<2> { '==' }
multi token m​:sep<1> { '=' }
multi token m​:sep<0> { '' }
token TOP { d <m> foo }
}

grammar g2 {
proto token m {*}
multi token m​:sep<0> { '' }
multi token m​:sep<1> { '=' }
multi token m​:sep<2> { '==' }
token TOP { d <m> foo }
}

g1.parse('d==foo').say; # 「d==foo」 m => 「==」
g1.parse('d=foo').say; # 「d=foo」 m => 「=」
g1.parse('dfoo').say; # 「dfoo」 m => 「」

g2.parse('d==foo').say; # (Any)
g2.parse('d=foo').say; # (Any)
g2.parse('dfoo').say; # 「dfoo」 m => 「」

# Also this​:
perl6 -e 'grammar g { proto regex { f {*} g } }'
===SORRY!=== Error while compiling -e
Proto regex body must be {*} (or <*> or <...>, which are deprecated)
at -e​:1
------> grammar g { proto regex ⏏{ f {*} g } }

...where the design docs say​:
The proto calls into the subdispatcher when it sees a * that cannot be a quantifier and is the only thing in its block. Therefore you can put items before and after the subdispatch by putting the * into curlies​:

  proto token foo { <prestuff> {*} <poststuff> }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.