Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pge named subrules and builtin rule behavior

0 views
Skip to first unread message

Jerry Gay

unread,
Nov 16, 2005, 11:11:24 AM11/16/05
to p6c
from a read of the spec, the expected behavior of this code is unclear to me.

in the rule, i'm matching the builtin whitespace rule, creating an
alias with the same name as the named rule, and matching the builtin
rule again. this brings up a few questions:

does the alias replace the named rule or coexist with it?
when does the binding of the alias to the pattern occur?

.sub 'main' :main
load_bytecode 'PGE.pbc'
load_bytecode 'PGE/dumper.pir'
.local pmc p6rule, rulesub, match
.local string target
.local int try

p6rule = find_global 'PGE', 'p6rule'
rulesub = p6rule('<ws> $<ws>:=(foo) <ws>')

try = 1

target = ' foo '
bsr Do_match

target = ' foofoo'
bsr Do_match

target = 'foofoofoo'
bsr Do_match

goto End

Do_match:
match = rulesub(target)
print 'match #'
print try
print "\n"
match.'dump'()
print "\n"
inc try
ret
End:
.end

here's what pge currently does, but i'm not certain this behavior is
correct, because it's implementation is not yet complete.

match #1
: < foo @ 0> 0
<ws>[0]: < @ 0> 0
<ws>[1]: <foo @ 1> 0
<ws>[2]: < @ 4> 0

match #2
:0

match #3
:0

is this what you expected?
~jerry

Patrick R. Michaud

unread,
Nov 16, 2005, 11:46:11 AM11/16/05
to jerry gay, p6c
On Wed, Nov 16, 2005 at 08:11:24AM -0800, jerry gay wrote:
> from a read of the spec, the expected behavior of this code is unclear to me.
>
> in the rule, i'm matching the builtin whitespace rule, creating an
> alias with the same name as the named rule, and matching the builtin
> rule again. this brings up a few questions:
>
> does the alias replace the named rule or coexist with it?

It coexists.

> when does the binding of the alias to the pattern occur?

It essentially occurs when the rule is compiled; given

/ <ws> $<ws>:=(foo) <ws> /

we have three things capturing into $/<ws> in the same lexical
scope, thus $/<ws> will be an array of match objects.

Yes.

Pm

0 new messages