treetop-1.2.2 rails workaround
March 5th, 2008 • Uncategorized
This was originally posted to the treetop-development group on google
First of all thx a lot for this wonderful treetop! Now I can finally
start to write small parsers because it’s the ruby I love :)
Anyways, here are my comments on the issues encountered by Nick. (I
use treetop from within a rails app)
I admit I didn’t have to dig as deep as him (thx for all the digging
and the post in this group, it saved HOURS for me most probably!)
1) To get my app running in development mode, I had to comment out the
following in treetop-1.2.2/lib/treetop.rb
# require “facets/stylize”
The funny thing is, if I don’t do that, it doesn’t break my whole app
like Nick said, but only some of my calls to
skip_before_filter which don’t stop the before_filters from
being executed anymore (The only failure I noticed in my app, was that
I couldn’t access actions that relied on skipping a before_filter that
was defined in ApplicationController – then again, my
SessionController – login/logout actions – relied on that very
behavior … and didn’t break :-) … I definitely assume that there
is no real problem with rails before_filters in general, but that this
also has something to do with problems related to constant loading
(i.e. camelize), still it’s funny that this seems to impact my app
only in this one scenario …
2) To get my app running in production mode though, I had to comment
out the following in treetop-1.2.2/lib/treetop.rb
# require “facets/stylize” # require “polyglot” # Polyglot.register([“treetop”, “tt”], Treetop)
I suppose this doesn’t lead to any problems, since these libs are only
necessary for generating the parser and not for executing it? The
thing here is that polyglot obviously offends rails’ production mode,
since both mongrel and thin both barf on me when I try to access any
actions.
To be more specific, if I require the .treetop file (as should be
possible thx to polyglot), then my server won’t start at all, telling
me friendly things like
../polyglot-0.2.0/lib/polyglot.rb:35:in `load’: undefined local variable or method `load_error’ for Polyglot:Module (NameError)
If I load the grammar via Treetop.load, the server starts up, but fails
on every action (the first failure is the same as the above, after
this all subsequent failures seem to be rooted in
load_missing_constant errors most probably due to the behavior that
Nick mentioned.
So for all that are experiencing similar problems:
My current workflow is to leave the require statements on my dev box
while I’m working on the grammar (knowing that I cannot access my app
properly during that time), and having them commented out in the
treetop installation on my production server (and also when I’m
accessing my app on my dev box)