Skip to content

Commit

Permalink
[api] Updated tag lexing and parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Sep 3, 2010
1 parent 414f184 commit 0402e99
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion examples/simple.feature
Expand Up @@ -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
"""
Expand Down
11 changes: 8 additions & 3 deletions lib/kyuri/lexer.js
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
},

Expand Down
9 changes: 6 additions & 3 deletions lib/kyuri/parser.js
Expand Up @@ -128,7 +128,7 @@ var _states = {
'TERMINATOR': {
value: '*',
next: 'featureDescription',
last: ['SENTENCE', 'TERMINATOR']
last: ['SENTENCE', 'TERMINATOR', 'INDENT']
},
'SENTENCE': {
value: '*',
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -383,7 +384,7 @@ Parser.prototype = {
},

checkTag: function (token) {
this.tag = token[1];
this.tags.push(token[1]);
this.hasTag = true;
},

Expand Down Expand Up @@ -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;
}

Expand All @@ -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]);
},

Expand Down
4 changes: 2 additions & 2 deletions test/parser-test.js
Expand Up @@ -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.