Skip to content
Browse files

used a modified patch made by @vslinko - see #109

  • Loading branch information...
1 parent b5bd31a commit 6fa8f93466da4535937ebbcd56a2d0a9e84874a9 @bclozel bclozel committed with ldegen Mar 20, 2013
Showing with 12 additions and 4 deletions.
  1. +12 −4 lib/cucumber/parser.js
View
16 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,22 @@ 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);
+ var languageMatch = /^# language: ([a-z_]*)/.exec(featureSource.toString());
+ var language = languageMatch == null ? 'en' : languageMatch[1];
+ lexer(language).scan(featureSource);
}
return features;
},

0 comments on commit 6fa8f93

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