Hi,

This should work well: all parsers are atoms as well, so you just
> concatenate them. And since rules memoize the parsers generated anyway,
> you'll only create one instance per FooBarParser instance. This means
> that the following tricks are not needed!
>

OK, thanks for the info!

In a related note; I have been trying to embed my expression-related
transformations into my expression grammar and have them automatically
applied when the parse() method is called. I want to encapsulate the
transformations along with the grammar rules, so that my AST is always
returned, not the PORO tree.

 I tried this:

class ExpressionParser < Parselet::Parser
    def parse(*args)
       self.transform(super(*args))
    end
end

 This works fine when you call the parse() method on an instance of this
class; but it doesn't get called when this grammar is composed into another
parent grammar. I suspect that this is because it is invoked by it's try()
method, so instead I tried this:

  def try(source, context)
        result = super(source, context)

        unless result.error?
            success(transform(flatten(result.result)))
        end
  end

Which works, but feels evil. Is there an easier way to do this? I want do
avoid the "do all your parsing first, then do all your transforms" approach,
because it feels right that my Expression class should own everything to do
with expressions.

cheers

ant

Reply via email to