From b68c17e7bcc4ca14c83735669b9b4ef6efc2f510 Mon Sep 17 00:00:00 2001
From: Robert Ferney <capnregex@gmail.com>
Date: Thu, 19 Jan 2012 17:49:53 -0700
Subject: [PATCH 1/3] ensure that the script exit

---
 bin/kyuri | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/bin/kyuri b/bin/kyuri
index 00e6f39..16d98c9 100755
--- a/bin/kyuri
+++ b/bin/kyuri
@@ -127,6 +127,10 @@ catch (err) {
 var _waitComplete = function () {
   if (!complete) {
     process.nextTick(_waitComplete);
+  } else { 
+    // make sure the script exits even if something we are testing has anohter
+    // wait for next tick loop going. 
+    process.exit();
   }
 };
 

From 26cb2d189ac6e7415f008dc3175e8707c1e57c0d Mon Sep 17 00:00:00 2001
From: Robert Ferney <capnregex@gmail.com>
Date: Mon, 30 Jan 2012 12:16:53 -0700
Subject: [PATCH 2/3] allow for space as indent in feature file

---
 examples/complex_space.feature | 31 +++++++++++++++++++++++++++++++
 lib/kyuri/lexer.js             | 22 +++++++++++++++++-----
 test/parser-test.js            | 10 +++++++++-
 3 files changed, 57 insertions(+), 6 deletions(-)
 create mode 100644 examples/complex_space.feature

diff --git a/examples/complex_space.feature b/examples/complex_space.feature
new file mode 100644
index 0000000..76a0ede
--- /dev/null
+++ b/examples/complex_space.feature
@@ -0,0 +1,31 @@
+Feature: Complex Addition
+  In order to avoid silly mistakes
+  As a math idiot
+  I want to be told the sum of two numbers
+
+  Background:
+    Given I have a calculator
+
+  Scenario: Add two numbers
+    Given I have entered "50" and "75" into the calculator
+    And I have entered 70 into the calculator
+    When I press add
+    Then the result should be 120 on the screen
+
+  Scenario Outline: Add three numbers
+    Given I have entered <number1> into the calculator
+    And I have entered <number2> into the calculator
+    And I have entered 120 into the calculator
+    When I press add
+    Then the result should be <number3> on the screen
+    
+    Examples:
+      | number1 | number2 | number3 |
+      | 10      | 20      | 150     |
+      | 20      | 40      | 180     |
+      
+  Scenario: Add two numbers
+    Given I have entered 50 into the calculator
+    And I have entered 70 into the calculator
+    When I press add
+    Then the result should be 120 on the screen
diff --git a/lib/kyuri/lexer.js b/lib/kyuri/lexer.js
index 862da30..3f8cf55 100644
--- a/lib/kyuri/lexer.js
+++ b/lib/kyuri/lexer.js
@@ -9,7 +9,7 @@
 var helpers = require('./helpers'),
     eyes = require('eyes');
 
-var MULTI_DENT        = /^(\t+)(\.)?/,
+var MULTI_DENT          = /^([\t ]+)(\.)?/,
     IS_EXAMPLE_ROW    = /^([\|\s+\S+]+\s+\|\s*)$/,
     PARSE_EXAMPLE_ROW = /\|[^|]+/gi,
     PYSTRING          = /"""/,
@@ -72,6 +72,7 @@ Lexer.prototype = {
     this.source = source;                  // Source code we are attempting to lex
     this.lineNum = 0;                      // Line number of the lexing operation
     this.indents = 0;                      // Number of indents
+    this.indent_size = null;               // tabstop
     this.tokens = [];                      // Stream of parsed tokens in the form ['TYPE', value, line]
     this.lines = this.source.split('\n');  // Split the source code by \n since we have no multi-line statements
     
@@ -232,20 +233,31 @@ Lexer.prototype = {
   },
   
   lineToken: function () {
-    var diff, indent, size;
-    if (!(indent = this.match(MULTI_DENT, 1))) {
+    var diff, size, indent;
+    if (this.i > 0) { // only check line token at the first of the line.
+      return false;
+    }
+    indent = this.match(MULTI_DENT, 1);
+    if (!indent) {
       return false;
     }
     
     size = indent.length;
     this.i += size;
+
+    if (!this.indent_size)  { // assume that first indent is one tabstop
+      this.indent_size = size;
+    }
     
     if (size > this.indents) {
       diff = size - this.indents;
+      diff = Math.round(diff / this.indent_size);
       this.token('INDENT', diff);
     } 
     else if (size < this.indents) {
-      this.token('OUTDENT', this.indents - size);
+      diff = this.indents - size;
+      diff = Math.round(diff / this.indent_size);
+      this.token('OUTDENT', diff);
     }
     
     this.indents = size;
@@ -294,4 +306,4 @@ Lexer.prototype = {
   }
 };
 
-exports.Lexer = Lexer;
\ No newline at end of file
+exports.Lexer = Lexer;
diff --git a/test/parser-test.js b/test/parser-test.js
index ba17261..d25f5e1 100644
--- a/test/parser-test.js
+++ b/test/parser-test.js
@@ -54,6 +54,14 @@ vows.describe('kyuri/parser').addBatch({
         assert.isObject(ast);  
         assert.include(ast, 1);
       }
+    },
+    "parsing complex_space.feature": {
+      topic: parseAllLines(path.join(__dirname, '..', 'examples', 'complex_space.feature')),
+      "should parse correctly": function (err, ast) {
+        assert.isNull(err);
+        assert.isObject(ast);  
+        assert.include(ast, 1);
+      }
     }
   }
-}).export(module);
\ No newline at end of file
+}).export(module);

From e004c16b725686665a9feb4736bbf1b07253f199 Mon Sep 17 00:00:00 2001
From: Robert Ferney <capnregex@gmail.com>
Date: Tue, 20 Mar 2012 11:14:17 -0600
Subject: [PATCH 3/3] adding Makefile

---
 Makefile | 12 ++++++++++++
 1 file changed, 12 insertions(+)
 create mode 100644 Makefile

diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..dd79ee4
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+
+
+test: vows kyuri
+
+vows:
+	vows --spec
+
+kyuri:
+	./bin/kyuri examples
+
+.PHONY: test vows kyuri
+