Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Load gherkin parser considering language comment #109

Closed
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+15 −4
Split
View
@@ -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;
},