private Tuple<List<GherkinParseEvent>, List<Feature>> Parse(string content) { var features = new List<Feature>(); var nBehaveConfiguration = NBehaveConfiguration.New.DontIsolateInAppDomain().SetDryRun(true); var gherkinScenarioParser = new GherkinScenarioParser(nBehaveConfiguration); gherkinScenarioParser.FeatureEvent += (s, e) => features.Add(e.EventInfo); var gherkinEventListener = new GherkinEventListener(); IListener listener = new CompositeGherkinListener(gherkinEventListener, gherkinScenarioParser); var newEvents = new List<GherkinParseEvent>(); var parser = new Parser(listener); try { parser.Scan(content); } catch (Exception e) { var match = new Regex(@"^Line: (?<lineNumber>\d+). (\w+\s*)+ '(?<lineText>.*)'$").Match(e.Message); if (match.Success && (e is ParseException)) { var line = int.Parse(match.Groups["lineNumber"].Value); var lineInFile = new LineInFile(line - 1); var text = match.Groups["lineText"].Value; var token = new Token(text, lineInFile); var error = new Token(e.Message, lineInFile); newEvents.Add(new GherkinParseEvent(GherkinTokenType.SyntaxError, token, error)); } } finally { newEvents.AddRange(ToZeroBasedLines(gherkinEventListener).ToList()); } return new Tuple<List<GherkinParseEvent>, List<Feature>>(newEvents, features); }
public void Parse(string fileToParse) { file = fileToParse; var content = File.ReadAllText(fileToParse); var gherkinParser = new Parser(this); gherkinParser.Scan(content); }