public void Examples(Token keyword, Token name) { listeners.ForEach(_ => _.Examples(keyword, name)); }
public void Feature(Token keyword, Token title, Token narrative) { events.Add(new GherkinParseEvent(GherkinTokenType.Feature, keyword, title, narrative)); }
public void Step(Token keyword, Token name) { events.Add(new GherkinParseEvent(GherkinTokenType.Step, keyword, name)); }
public void Background(Token keyword, Token name) { events.Add(new GherkinParseEvent(GherkinTokenType.Background, keyword, name)); }
public void DocString(Token docString) { events.Add(new GherkinParseEvent(GherkinTokenType.DocString, docString)); }
public void Step(Token keyword, Token name) { string stepText = string.Format("{0} {1}", keyword.Content, name.Content); var stringStep = new StringStep(stepText, file, keyword.LineInFile.Line); events.Enqueue(new StepEvent(stepText, e => StepEvent.Invoke(this, new EventArgs<StringStep>(stringStep)))); }
public void Background(Token keyword, Token name) { var scenario = new Scenario(name.Content, file, currentFeature, keyword.LineInFile.Line); currentScenario = scenario; events.Enqueue(new BackgroundEvent(currentScenario, e => BackgroundEvent.Invoke(this, new EventArgs<Scenario>(scenario)))); }
private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTitle(SnapshotSpan span, Token token, GherkinTokenType tokenType) { var spanText = span.GetText(); var tokenText = token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(_ => _.Trim(WhiteSpaces.Chars)).ToList(); foreach (var row in tokenText) { var idx = spanText.IndexOf(row, StringComparison.CurrentCulture); if (idx == -1) continue; ITextSnapshotLine containingLine = span.Start.GetContainingLine(); var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, row.Length)); var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType)); yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan); } }
private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> HandleType(SnapshotSpan span, Token token, GherkinTokenType tokenType) { var text = span.GetText(); if (text.TrimStart(WhiteSpaces.Chars).StartsWith(token.Content)) { var idx = text.IndexOf(token.Content, StringComparison.Ordinal); ITextSnapshotLine containingLine = span.Start.GetContainingLine(); var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, token.Content.Length)); var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType)); return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan); } return null; }
public void Tag(Token name) { listeners.ForEach(_ => _.Tag(name)); }
private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleComment(SnapshotSpan span, GherkinParseEvent evt) { var text = span.GetText(); var isLanguage = new Regex(@"\s*#\s*language\s*(:|\s)\s*(?<language>[a-zA-Z\-]+)"); var match = isLanguage.Match(text); if (match.Success) { foreach (var commentTag in TagLanguageComment(span, evt, match, text)) yield return commentTag; } else { var r = new Regex(string.Format(@"^\s*#\s*{0}\s*$", evt.Tokens[0].Content)); if (r.IsMatch(text)) { var t = new Token(text, evt.Tokens[0].LineInFile); var tag = CreateTag(t, span, evt); if (tag != null) yield return tag; } } }
public void Step(Token keyword, Token name) { listeners.ForEach(_ => _.Step(keyword, name)); }
public void Scenario(Token keyword, Token title) { listeners.ForEach(_ => _.Scenario(keyword, title)); }
public void Feature(Token keyword, Token title, Token narrative) { listeners.ForEach(_ => _.Feature(keyword, title, narrative)); }
public void Feature(Token keyword, Token title, Token narrative) { CreateFeature(title.Content, narrative.Content, keyword.LineInFile.Line); }
private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> SyntaxError(SnapshotSpan span, GherkinParseEvent evt) { var text = span.GetText(); var token = new Token(text, new LineInFile(-1)); var tag = CreateTag(token, span, GherkinTokenType.SyntaxError, text); if (tag != null) yield return tag; }
public void Scenario(Token keyword, Token title) { var scenario = new Scenario(title.Content, file, currentFeature, keyword.LineInFile.Line); currentScenario = scenario; events.Enqueue(new ScenarioEvent(currentScenario, e => { scenario.AddTags(e.Tags); ScenarioEvent.Invoke(this, new EventArgs<Scenario>(scenario)); })); }
private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> TagLanguageComment(SnapshotSpan span, GherkinParseEvent evt, Match match, string text) { var i = text.IndexOf("language"); var t1 = new Token(text.Substring(0, i), evt.Tokens[0].LineInFile); var comment = CreateTag(t1, span, evt); if (comment != null) yield return comment; var t2 = new Token(match.Value.Substring(i), evt.Tokens[0].LineInFile); var lang = CreateTag(t2, span, new GherkinParseEvent(GherkinTokenType.Tag, evt.Tokens.ToArray())); if (lang != null) yield return lang; var t3 = new Token(text.Substring(i + t2.Content.Length).TrimEnd(WhiteSpaces.Chars), evt.Tokens[0].LineInFile); if (t3.Content != "") { var end = CreateTag(t3, span, evt); if (end != null) yield return end; } }
public void Tag(Token tag) { events.Enqueue(new TagEvent(tag.Content, e => TagEvent.Invoke(this, new EventArgs<string>(tag.Content)))); }
private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt) { var text = span.GetText(); return CreateTag(token, span, evt.GherkinTokenType, text); }
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); }
private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinTokenType tokenType, string text) { foreach (var row in token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries)) { string rowText = row.Trim(WhiteSpaces.Chars); var idx = text.IndexOf(rowText, StringComparison.Ordinal); if (idx == -1) continue; ITextSnapshotLine containingLine = span.Start.GetContainingLine(); var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, rowText.Length)); var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType)); return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan); } return null; }
public void Comment(Token comment) { events.Add(new GherkinParseEvent(GherkinTokenType.Comment, comment)); }
public void Comment(Token comment) { }
public void Examples(Token keyword, Token name) { events.Add(new GherkinParseEvent(GherkinTokenType.Examples, keyword, name)); }
public void DocString(Token docString) { var docStringText = docString.Content; events.Enqueue(new DocStringEvent(docStringText, e => DocStringEvent.Invoke(this, new EventArgs<string>(docStringText)))); }
public void Scenario(Token keyword, Token title) { events.Add(new GherkinParseEvent(GherkinTokenType.Scenario, keyword, title)); }
public void Examples(Token keyword, Token name) { events.Enqueue(new ExamplesEvent(e => ExamplesEvent.Invoke(this, new EventArgs()))); }
public void Tag(Token tag) { if (tag.Content != "@") //bug in gherkin parser? { var previous = events.LastOrDefault() ?? new GherkinParseEvent(GherkinTokenType.SyntaxError); if (previous.GherkinTokenType == GherkinTokenType.Tag && tag.LineInFile.Line == previous.Tokens[0].LineInFile.Line) previous.Tokens.Add(tag); else events.Add(new GherkinParseEvent(GherkinTokenType.Tag, tag)); } }
public void DocString(Token docString) { listeners.ForEach(_ => _.DocString(docString)); }