[rspec-users] External Dependencies (was Multi-line steps)

aslak hellesoy aslak.hellesoy at gmail.com
Wed Apr 9 09:11:02 EDT 2008

On Wed, Apr 9, 2008 at 2:41 PM, David Chelimsky <dchelimsky at gmail.com> 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*

  rule header
    'Story: ' sentence_line

  rule narrative
    'As a' sentence_line

  rule scenario
    'Scenario: ' sentence_line step*

  rule step
    # The various step rules are generated dynamically
    'Given ' (step_1 / step_2)

  # Dynamically generated rule
  rule step_1
    'I am ' word ' and ' word

  # Dynamically generated rule
  rule step_2
    'I was ' word ' and ' word

  rule word

  rule sentence_line
    (!eol .)* eol

  rule eol
    "\n" / eof

  rule eof

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!


>  _______________________________________________
>  rspec-users mailing list
>  rspec-users at rubyforge.org
>  http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list