> Firstly, if I have a transform like this:
>
> rule(foo: sequence(:bar)) { some_method(bar) }
>
> and some_method decides that, having examined 'bar', it doesn't actually
> want to replace it after all, so it just returns 'bar'. ie no change.
> However, from the Transformation's view point, this rule successfully
> matched, so no further matches are attempted. For example, if I instead had:
>
> rule(foo: sequence(:bar)) { some_method(bar) } #
> some_method() returns 'bar' ie no change
> rule(foo: sequence(:bar)) { some_other_method(bar) }
>
> then the second rule (and some_other_method()) never fire.
>
> Is there some way to programmatically say, "this rule didn't match" ?
> Currently I wrap all these up in one single function, which is
> probably more efficient anyway, but I'm curious.
Curiosity killed the cat ;) Have a look at parslet/pattern/binding.rb –
The right way to do this IMHO is to create a binding that only matches
the right kind of :bar!
No other way for saying: Hey I didn't match. Because.. in a way, once
the block is executed, semantically parslet has a match. This is why I
propose to hook into the matching directly.
> Secondly, given that you can do this:
>
> rule( str('foo'), str('bar') ) { ...}
>
> can you do something like this?
>
> rule(SomeClass, SomeOtherClass) {...} # these classes are constructed
> by earlier rules matching
None of these look like syntax to me - are we still talking about
transformations? You could do
rule([str('foo'), str('bar')]) { ... }
which would probably match [str('foo'), str('bar')] (duh), but other
than that? Can you provide a running sample for the former?
Or are you looking for a generalized Ruby class hierarchy transformer?
(Because I am ;))
kaspar