Skip to content
Browse files

Load gherkin parser considering language comment

  • Loading branch information...
1 parent 1d16d85 commit 4b1cf13d17f30f94e347ed7ec2b4c99c7c32edba @vslinko vslinko committed Jan 28, 2013
Showing with 15 additions and 4 deletions.
  1. +15 −4 lib/cucumber/parser.js
View
19 lib/cucumber/parser.js
@@ -1,6 +1,5 @@
var Parser = function(featureSources, astFilter) {
var Gherkin = require('gherkin');
- var GherkinLexer = require('gherkin/lib/gherkin/lexer/en');
var Cucumber = require('../cucumber');
var features = Cucumber.Ast.Features();
@@ -9,13 +8,25 @@ var Parser = function(featureSources, astFilter) {
var self = {
parse: function parse() {
- var eventHandler = self.getEventHandlers();
- var lexer = new GherkinLexer(self.getEventHandlers());
+ var lexers = {};
+ var lexer = function (lang) {
+ if (!(lang in lexers)) {
+ lexers[lang] = new (Gherkin.Lexer(lang))(self.getEventHandlers());
+ }
+
+ return lexers[lang];
+ };
+
for (i in featureSources) {
var currentSourceUri = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_URI_INDEX];
var featureSource = featureSources[i][Parser.FEATURE_NAME_SOURCE_PAIR_SOURCE_INDEX];
self.setCurrentSourceUri(currentSourceUri);
- lexer.scan(featureSource);
+ featureSource = featureSource.toString();
+
+ var languageMatch = /^# language: (.*)\n/.exec(featureSource);
+ var language = languageMatch == null ? 'en' : languageMatch[1];
+
+ lexer(language).scan(featureSource);
}
return features;
},

0 comments on commit 4b1cf13

Please sign in to comment.
Something went wrong with that request. Please try again.