On Wed, Apr 9, 2008 at 2:41 PM, David Chelimsky <[EMAIL PROTECTED]> wrote: > On Apr 9, 2008, at 8:13 AM, aslak hellesoy wrote: > > > I'm working on a Treetop (http://treetop.rubyforge.org/) > > implementation of the Story parser. > > Hey Aslak, while I love the idea of exploiting treetop for this, this > would be our first external dependency for end users. That was one of > the reasons I didn't use treetop in the first place - it had just been > released and Brian suggested exporing it when I was working on Plain > Text Stories. > > Personally, I'm in support of external dependencies, especially in > light of recent improvements to Rubygems that make it even easier for > a gem to manage its own dependencies. But thus far we've had an only > slightly-less-than-official policy of no external dependencies. Has > your thinking on this issue shifted as well?
I realize it will introduce a dependency on treetop, but now that rubygems are ubiquotous and has largely improved with 1.1.0 I think it's ok. It would only be needed for stories. A treetop based parser has several benefits: * Much simpler codebase * Much better error messages for users. Line numbers and conflict detection. * Easier integration with other tools (including rspec core) * Simpler setup for story running (I have a vague plan for that in my head). I haven't committed the code yet - for now it will live in a separate repo on GitHub. Here is a teaser for the grammar: grammar Story rule story header narrative scenario* end rule header 'Story: ' sentence_line end rule narrative 'As a' sentence_line end rule scenario 'Scenario: ' sentence_line step* end rule step # The various step rules are generated dynamically 'Given ' (step_1 / step_2) end # Dynamically generated rule rule step_1 'I am ' word ' and ' word end # Dynamically generated rule rule step_2 'I was ' word ' and ' word end rule word ([\w])* end rule sentence_line (!eol .)* eol end rule eol "\n" / eof end rule eof !. end end Basically, each run will be based on a core grammar which is extended by the user, creating extra rules for each parameterised step. The treetop based parser would create the grammar dynamically, compile it in-memory and use it to parse plain text stories. My first benchmarks are pretty good - 0.03 secs to parse/compile the grammar and less than 0.0001 secs to parse a simple story. This is fun! Aslak > _______________________________________________ > rspec-users mailing list > rspec-users@rubyforge.org > http://rubyforge.org/mailman/listinfo/rspec-users > _______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users