On 22/05/2013, at 9:17 AM, Paul Madden <
pma...@gmail.com> wrote:
> I read with interest Clifford's comment in this thread:
>
>
https://groups.google.com/forum/?fromgroups#!topic/treetop-dev/FJkgreiy4IY
>
> But does this require modifying the Treetop code itself, to use InputProxy in place of the input string? I'd rather not do that, but maybe I don't understand the suggestion. Like the OP in the second thread there, I was previously using a class variable for data sharing, but don't want to do that, either.
You can see how I use it here:
<
https://github.com/cjheath/activefacts/blob/master/lib/activefacts/cql/parser.rb>
Basically it's this:
class MyParser < TreetopGeneratedParser
class Context
...
end
class InputProxy
…
end
def parse(input, options = {})
input = InputProxy.new(input, context, self) unless input.respond_to?(:context)
super(input, options)
end
end
The "unless" is there in case a caller wanted to pass in a different kind of context.
as far as I know, that hasn't happened yet.
This makes it possible from anywhere in the parser (including in a sem-pred)
to say "input.context.whatever".
Clifford Heath.