Permalink
Browse files

[api] Updated tag lexing and parsing

  • Loading branch information...
1 parent 414f184 commit 0402e99a8d3e214b425a844ad9afb1fb3f50aa0e @indexzero indexzero committed Sep 3, 2010
Showing with 17 additions and 9 deletions.
  1. +1 −1 examples/simple.feature
  2. +8 −3 lib/kyuri/lexer.js
  3. +6 −3 lib/kyuri/parser.js
  4. +2 −2 test/parser-test.js
View
@@ -3,7 +3,7 @@ Feature: Addition #AND A COMMENT!!!
As a math idiot
I want to be told the sum of two numbers
- @tag1
+ @tag1 @tag2
#AND A COMMENT!!!
Scenario: Add two numbers
"""
View
@@ -14,7 +14,8 @@ var MULTI_DENT = /^(\t+)(\.)?/,
IS_EXAMPLE_ROW = /^([\|\s+\S+]+\s+\|\s*)$/,
PARSE_EXAMPLE_ROW = /\|\s*(\S+)/gi,
PYSTRING = /"""/,
- TAG = /@(\w+)/i,
+ TAGS_LENGTH = /[@\w+\s*]+/i,
+ TAGS = /@(\w+)/gi,
COMMENT = /#\s*([\S+\s+]+)/i,
SENTENCE = /([\S+\s+]+)/i,
SENTENCE_COMMENT = /([\S+\s+]+)#\s*([\S+\s+]+)/i;
@@ -181,12 +182,16 @@ Lexer.prototype = {
tagToken: function () {
var match;
- if (!(match = this.match(TAG))) {
+ if (!(match = this.match(TAGS))) {
return false;
}
+ for (var j = 0; j < match.length; j++) {
+ this.token('TAG', match[j].trim().replace('@',''));
+ }
+
+ match = this.match(TAGS_LENGTH);
this.i += match[0].length;
- this.token('TAG', match[1].trim());
return true;
},
View
@@ -128,7 +128,7 @@ var _states = {
'TERMINATOR': {
value: '*',
next: 'featureDescription',
- last: ['SENTENCE', 'TERMINATOR']
+ last: ['SENTENCE', 'TERMINATOR', 'INDENT']
},
'SENTENCE': {
value: '*',
@@ -343,6 +343,7 @@ Parser.prototype = {
this.ast = {};
this.isPystring = false;
this.hasTag = false;
+ this.tags = [];
this.states = Object.create(_states);
this.current = this.states['start'];
this.last = null;
@@ -383,7 +384,7 @@ Parser.prototype = {
},
checkTag: function (token) {
- this.tag = token[1];
+ this.tags.push(token[1]);
this.hasTag = true;
},
@@ -418,7 +419,7 @@ Parser.prototype = {
// If we have a tag, assign it to the current node
if (this.entity.indexOf(token[0]) !== -1 && this.hasTag) {
- this.node['tag'] = this.tag;
+ this.node['tags'] = this.tags;
this.hasTag = false;
}
@@ -442,6 +443,8 @@ Parser.prototype = {
return true;
}
+ eyes.inspect(this.last);
+ eyes.inspect(this.current);
throw new Error('Mismatched last token "' + this.last[0] + '" at line ' + this.last[2]);
},
View
@@ -43,13 +43,13 @@ vows.describe('kyuri/parser').addBatch({
assert.isNotNull(data.toString());
inspect(kyuri.parse(data.toString()));
}
- }/*,
+ },
"parsing complex.feature": {
topic: readAllLines(path.join(__dirname, '..', 'examples', 'complex.feature')),
"should parse correctly": function (err, data) {
assert.isNotNull(data.toString());
inspect(kyuri.parse(data.toString()));
}
- }*/
+ }
}
}).export(module);

0 comments on commit 0402e99

Please sign in to comment.