Bjørn --
I've had good luck with something along the following lines:
def extend_grammar(base_grammar,name,new_rules,new_top='super')
Treetop.load_from_string(%Q{
grammar #{name}
include #{base_grammar.name.sub(/Parser$/,'')}
rule top
#{new_top}
end
#{new_rules}
end
})
end
My version has more goo, but this is the core. With this you you can do
fun tricks like generating grammars at run-time, building trees of
grammars, etc. For your needs it sounds like you could just do it
literally in the grammar files (and skip the string manipulation) like
so:
grammar This_grammar
include Shared_grammar
rule top
# top rule for this grammar
end
#
# rules for this grammar
#
end
...with the comments replaced with the indicated content.
-- Markus
> --
Markus <
mar...@reality.com>