Hei Ant,
First: Thanks for all the kind words and the interesting questions!
> Oh, interesting. How does it match a 'sequence()' directive in the
> transform rule to a 'SequenceBind' object? Is it just string fu? Can I
> add a FooBind object and start using 'foo()' in rules?
Almost no -fu in parslet: look at parslet.rb
def sequence(symbol)
Pattern::SequenceBind.new(symbol)
end
module_function :sequence
So for your method (you might want to reconsider the name), you'd have
def foo(sym)
FooBind.new(symbol)
end
As long as FooBind quacks like a duck, you should be fine.
> Yeah, that one ;) I end up with a lot of entries like " [
> #<IntegerLiteral: 0x....>, #<BinaryOperator: 0x....> ] " so what I do is
> match generic sequences and figure out what to do in the transformation
> block. It would be cool to be able to say:
>
> rule(IntegerLiteral, BinaryOperator) {...}
Currently parslet uses #== for element comparison in arrays. This would
work here, but is not optimal. I am considering the switch to #=== -
which is certainly more appropriate.
But I feel another library lurking in there: What if I could also match
things inside classes that implement a matcher interface? Like:
Tree.new(left, right)
rule(Tree(some_left, some_right)) { ... }
? I think this would be awesome. Especially because I could use this to
do optimizing transformations on the parser ;) So yeah, maybe there is
another one along the lines of parslet transforms coming up. Think
pattern matching like Haskell has.
BTW: I guess you know that you can apply transformations in stages?
Nothing prevents you from reinjecting the first transformation result
into the second transformation.
cheers!
kaspar