self._getFeatureFileObjects = function (featureFilePath) { var parser = new Gherkin.Parser(); var gherkinDocument = parser.parse(FS.readFileSync(featureFilePath, 'utf8')); var featureFileObjects = []; var featureTags = self._collectTags(gherkinDocument.feature.tags); if (gherkinDocument.feature.children.length > 0) { gherkinDocument.feature.children.forEach(function (child) { var scenarioTags = self._collectTags(child.tags); if (child.examples === undefined || child.examples.length === 0) { featureFileObjects.push({ path: featureFilePath + ':' + child.location.line, tags: featureTags.concat(scenarioTags) }); } else { child.examples.forEach(function (example) { var exampleTags = self._collectTags(example.tags); example.tableBody.forEach(function (tableRow) { featureFileObjects.push({ path: featureFilePath + ':' + tableRow.location.line, tags: featureTags.concat(scenarioTags).concat(exampleTags) }); }); }); } }); } return featureFileObjects; };
// // private // _parseGherkin(gherkin) { const parser = new Gherkin.Parser(); parser.stopAtFirstError = false; const builder = new Gherkin.AstBuilder(); const scanner = new Gherkin.TokenScanner(gherkin); return parser.parse(scanner, builder, new Gherkin.TokenMatcher()); }
it('should parse gherkin input', () => { const parser = new Parser(); parser.stopAtFirstError = false; const ast = parser.parse(text); // console.log('Feature', ast.feature); // console.log('Scenario', ast.feature.children); // console.log('Steps', ast.feature.children[0].steps[0]); assert.ok(ast.feature); assert.ok(ast.feature.children); assert.ok(ast.feature.children[0].steps); });
fs.readFile(data, 'utf8', function (err, data) { if (err) { event.sender.send('asynchronous-reply', 'fileEdit', null); } if (data) { var parser = new Gherkin.Parser(); try { var gherkinDocument = parser.parse(data); } catch (e) { event.sender.send('asynchronous-reply', 'fileEdit', {success: false, data: e}); } event.sender.send('asynchronous-reply', 'fileEdit', {success: true, dataRaw: data, dataComposed: gherkinDocument}); } });
static parse({scenarioFilter, source, uri}) { let gherkinDocument try { gherkinDocument = gherkinParser.parse(source) } catch (error) { error.message += '\npath: ' + uri throw error } return new Feature({ gherkinData: gherkinDocument.feature, gherkinPickles: gherkinCompiler.compile(gherkinDocument, uri), scenarioFilter, uri }) }
function parse(file, encoding, callback) { if (file.isNull()) { return callback(null, file); } if (file.isStream()) { return callback(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); } try { parser.parse(file.contents.toString('utf8')); stream.push(file); return callback(); } catch (e) { var pluginError = chalk.red(e.message) + '\nat: ' + chalk.cyan(file.path); errors.push(pluginError); } return callback(); }
module.exports = function () { var parser = new gherkin.Parser(); var errors = []; var stream = through.obj(parse, report); function parse(file, encoding, callback) { if (file.isNull()) { return callback(null, file); } if (file.isStream()) { return callback(new gutil.PluginError(PLUGIN_NAME, 'Streaming not supported')); } try { parser.parse(file.contents.toString('utf8')); stream.push(file); return callback(); } catch (e) { var pluginError = chalk.red(e.message) + '\nat: ' + chalk.cyan(file.path); errors.push(pluginError); } return callback(); } function report(callback) { if (errors.length > 0) { stream.emit('error', new gutil.PluginError(PLUGIN_NAME, { message: '\n' + errors.join('\n'), showStack: false })); } callback(); } return stream; };
/** * Decorate a file object with a data structure of its parsed contents. * @param Object file Object representing a file. * @return Object The decorated file object. */ function processFileContent(file) { var fileContent = file.content; if (!fileContent || !fileContent.length) { file.empty = true; } try { if (file.isFeatureFile) { file.data = featureParser.parse(fileContent); } else if(file.isMarkdownFile) { file.data = markdown.parse(fileContent); file.html = markdown.renderJsonML(markdown.toHTMLTree(fileContent)); } else { file.data = false; } } catch (err) { file.data = false; file.error = err; } return file; }
function parseGherkin(str){ var parser = new gherkin.Parser(); return parser.parse(str).scenarioDefinitions; }
parse: function parse(text) { return parser.parse(text); }
files.forEach(function (file) { var fileContent = fs.readFileSync(file, 'utf8'); var parser = new gherkin.Parser(); var feature = parser.parse(fileContent); describeFeature(feature); });