Best Gherkin-dotnet code snippet using Gherkin.Token
GherkinStepTagger.cs
Source:GherkinStepTagger.cs
...12 public static readonly char[] Chars = new[] { '\t', ' ', '\r', '\n' };13 }14 public class GherkinStepTagger15 {16 private readonly Dictionary<GherkinTokenType, Func<SnapshotSpan, GherkinParseEvent, IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>>> tagHandler;17 private bool cellToggle;18 public GherkinStepTagger()19 {20 tagHandler = new Dictionary<GherkinTokenType, Func<SnapshotSpan, GherkinParseEvent, IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>>>21 {22 {GherkinTokenType.SyntaxError, SyntaxError},23 {GherkinTokenType.Feature, HandleFeature},24 {GherkinTokenType.Scenario, HandleScenario},25 {GherkinTokenType.Background, HandleBackground},26 {GherkinTokenType.Comment, HandleComment},27 {GherkinTokenType.Tag, HandleTag},28 {GherkinTokenType.DocString, HandleDocString},29 {GherkinTokenType.Examples, HandleSpan},30 {GherkinTokenType.Step, HandleStep},31 {GherkinTokenType.TableHeader, HandleTableHeader},32 {GherkinTokenType.TableCell, HandleTableCell},33 };34 }35 public IEnumerable<ITagSpan<GherkinTokenTag>> CreateTags(IEnumerable<GherkinParseEvent> events, SnapshotSpan span)36 {37 var value = span.GetText();38 if (string.IsNullOrWhiteSpace(value))39 return new ITagSpan<GherkinTokenTag>[0];40 var tags = new List<ITagSpan<GherkinTokenTag>>();41 var line = span.Start.GetContainingLine();42 int lineNumber = line.LineNumber;43 var evt = FindMatchingEvent(events, lineNumber);44 if (evt != null)45 {46 Func<SnapshotSpan, GherkinParseEvent, IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>> tagger;47 if (tagHandler.TryGetValue(evt.GherkinTokenType, out tagger))48 {49 var items = tagger(span, evt).ToList();50 var intersectingTags = items.Where(_ => _.Item1.IntersectsWith(span)).Select(_ => _.Item2);51 tags.AddRange(intersectingTags);52 }53 }54 return tags;55 }56 private GherkinParseEvent FindMatchingEvent(IEnumerable<GherkinParseEvent> events, int lineNumber)57 {58 var evt = events.FirstOrDefault(_ => _.Tokens.Any(λ => λ.LineInFile.Line == lineNumber))59 ?? events.Where(_ => _.Tokens.Any(λ => λ.LineInFile.Line < lineNumber))60 .OrderByDescending(_ => _.Tokens.First().LineInFile.Line)61 .FirstOrDefault();62 if (evt != null && evt.GherkinTokenType == GherkinTokenType.SyntaxError && lineNumber > evt.Tokens.Max(_ => _.LineInFile.Line))63 return null;64 return evt;65 }66 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleSpan(SnapshotSpan span, GherkinParseEvent evt)67 {68 ITextSnapshotLine containingLine = span.Start.GetContainingLine();69 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));70 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));71 yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);72 }73 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleFeature(SnapshotSpan span, GherkinParseEvent evt)74 {75 if (!evt.Tokens.Any())76 yield break;77 var t1 = HandleType(span, evt.Tokens.First(), GherkinTokenType.Feature);78 if (t1 != null) yield return t1;79 if (evt.Tokens.Count >= 2)80 {81 var t2 = HandleTitle(span, evt.Tokens[1], GherkinTokenType.FeatureTitle);82 foreach (var tuple in t2)83 yield return tuple;84 }85 if (evt.Tokens.Count == 3)86 {87 var t3 = HandleTitle(span, evt.Tokens[2], GherkinTokenType.FeatureDescription);88 foreach (var tuple in t3)89 yield return tuple;90 }91 }92 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleScenario(SnapshotSpan span, GherkinParseEvent evt)93 {94 return HandleTag(span, evt, GherkinTokenType.Scenario, GherkinTokenType.ScenarioTitle);95 }96 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleBackground(SnapshotSpan span, GherkinParseEvent evt)97 {98 return HandleTag(span, evt, GherkinTokenType.Background, GherkinTokenType.BackgroundTitle);99 }100 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleStep(SnapshotSpan span, GherkinParseEvent evt)101 {102 return HandleTag(span, evt, GherkinTokenType.Step, GherkinTokenType.StepText);103 }104 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt)105 {106 var tags = new List<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>();107 foreach (var token in evt.Tokens)108 tags.AddRange(HandleTitle(span, token, GherkinTokenType.Tag));109 return tags;110 }111 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleComment(SnapshotSpan span, GherkinParseEvent evt)112 {113 var text = span.GetText();114 var isLanguage = new Regex(@"\s*#\s*language\s*(:|\s)\s*(?<language>[a-zA-Z\-]+)");115 var match = isLanguage.Match(text);116 if (match.Success)117 {118 foreach (var commentTag in TagLanguageComment(span, evt, match, text))119 yield return commentTag;120 }121 else122 {123 var r = new Regex(string.Format(@"^\s*#\s*{0}\s*$", evt.Tokens[0].Content));124 if (r.IsMatch(text))125 {126 var t = new Token(text, evt.Tokens[0].LineInFile);127 var tag = CreateTag(t, span, evt);128 if (tag != null)129 yield return tag;130 }131 }132 }133 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> TagLanguageComment(SnapshotSpan span, GherkinParseEvent evt, Match match, string text)134 {135 var i = text.IndexOf("language");136 var t1 = new Token(text.Substring(0, i), evt.Tokens[0].LineInFile);137 var comment = CreateTag(t1, span, evt);138 if (comment != null)139 yield return comment;140 var t2 = new Token(match.Value.Substring(i), evt.Tokens[0].LineInFile);141 var lang = CreateTag(t2, span, new GherkinParseEvent(GherkinTokenType.Tag, evt.Tokens.ToArray()));142 if (lang != null)143 yield return lang;144 var t3 = new Token(text.Substring(i + t2.Content.Length).TrimEnd(WhiteSpaces.Chars), evt.Tokens[0].LineInFile);145 if (t3.Content != "")146 {147 var end = CreateTag(t3, span, evt);148 if (end != null)149 yield return end;150 }151 }152 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> SyntaxError(SnapshotSpan span, GherkinParseEvent evt)153 {154 var text = span.GetText();155 var token = new Token(text, new LineInFile(-1));156 var tag = CreateTag(token, span, GherkinTokenType.SyntaxError, text);157 if (tag != null)158 yield return tag;159 }160 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableHeader(SnapshotSpan span, GherkinParseEvent evt)161 {162 cellToggle = false;163 return TableItem(span, evt.GherkinTokenType);164 }165 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableCell(SnapshotSpan span, GherkinParseEvent evt)166 {167 var tokenType = cellToggle ? GherkinTokenType.TableCell : GherkinTokenType.TableCellAlt;168 cellToggle = !cellToggle;169 return TableItem(span, tokenType);170 }171 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> TableItem(SnapshotSpan span, GherkinTokenType tokenType)172 {173 return HandleText(span, tokenType, "|");174 }175 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleDocString(SnapshotSpan span, GherkinParseEvent evt)176 {177 var text = span.GetText().Trim(WhiteSpaces.Chars);178 if (text == "\"\"\"")179 return HandleText(span, GherkinTokenType.Tag, "\"");180 //TODO: dont color the spaces that will be removed181 ITextSnapshotLine containingLine = span.Start.GetContainingLine();182 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));183 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));184 return new[] { new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan) };185 }186 private static IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleText(187 SnapshotSpan span, GherkinTokenType tokenType,188 string surroundingText)189 {190 var str = span.GetText().TrimEnd(WhiteSpaces.Chars);191 var idx = str.IndexOf(surroundingText, StringComparison.InvariantCulture);192 var idx2 = str.LastIndexOf(surroundingText, StringComparison.InvariantCulture);193 if (idx == -1 || idx2 == -1)194 yield break;195 ITextSnapshotLine containingLine = span.Start.GetContainingLine();196 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, idx2 - idx + 1));197 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));198 yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);199 }200 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt, GherkinTokenType tokenType, GherkinTokenType tokenTitleType)201 {202 if (!evt.Tokens.Any())203 yield break;204 var t1 = HandleType(span, evt.Tokens.First(), tokenType);205 if (t1 != null) yield return t1;206 if (evt.Tokens.Count >= 2)207 {208 var t2 = HandleTitle(span, evt.Tokens[1], tokenTitleType);209 foreach (var tuple in t2)210 yield return tuple;211 }212 }213 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> HandleType(SnapshotSpan span, Token token, GherkinTokenType tokenType)214 {215 var text = span.GetText();216 if (text.TrimStart(WhiteSpaces.Chars).StartsWith(token.Content))217 {218 var idx = text.IndexOf(token.Content, StringComparison.Ordinal);219 ITextSnapshotLine containingLine = span.Start.GetContainingLine();220 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, token.Content.Length));221 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));222 return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);223 }224 return null;225 }226 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTitle(SnapshotSpan span, Token token, GherkinTokenType tokenType)227 {228 var spanText = span.GetText();229 var tokenText = token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries).Select(_ => _.Trim(WhiteSpaces.Chars)).ToList();230 foreach (var row in tokenText)231 {232 var idx = spanText.IndexOf(row, StringComparison.CurrentCulture);233 if (idx == -1)234 continue;235 ITextSnapshotLine containingLine = span.Start.GetContainingLine();236 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, row.Length));237 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));238 yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);239 }240 }241 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt)242 {243 var text = span.GetText();244 return CreateTag(token, span, evt.GherkinTokenType, text);245 }246 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinTokenType tokenType, string text)247 {248 foreach (var row in token.Content.Split(new[] { '\n' }, StringSplitOptions.RemoveEmptyEntries))249 {250 string rowText = row.Trim(WhiteSpaces.Chars);251 var idx = text.IndexOf(rowText, StringComparison.Ordinal);252 if (idx == -1)253 continue;254 ITextSnapshotLine containingLine = span.Start.GetContainingLine();255 var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position + idx, rowText.Length));256 var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(tokenType));257 return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);258 }259 return null;260 }261 }262}...
GherkinParser.cs
Source:GherkinParser.cs
...9{10 public class GherkinParser : IParser11 {12 // ReSharper disable once InconsistentNaming13 private static readonly NodeTypeSet SCENARIO_END_TOKENS = new NodeTypeSet(GherkinTokenTypes.BACKGROUND_KEYWORD,14 GherkinTokenTypes.SCENARIO_KEYWORD,15 GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD,16 GherkinTokenTypes.RULE_KEYWORD,17 GherkinTokenTypes.FEATURE_KEYWORD);18 private readonly ILexer _lexer;19 private readonly IPsiSourceFile _sourceFile;20 public GherkinParser(ILexer lexer, IPsiSourceFile sourceFile)21 {22 _lexer = lexer;23 _sourceFile = sourceFile;24 }25 public IFile ParseFile()26 {27 using (var lifetimeDefinition = Lifetime.Define())28 {29 var builder = new PsiBuilder(_lexer, GherkinNodeTypes.FILE, null, lifetimeDefinition.Lifetime);30 var fileMarker = builder.Mark();31 while (!builder.Eof())32 {33 var tokenType = builder.GetTokenType();34 if (tokenType == GherkinTokenTypes.FEATURE_KEYWORD)35 ParseFeature(builder);36 else if (tokenType == GherkinTokenTypes.TAG)37 ParseTags(builder);38 else39 builder.AdvanceLexer();40 }41 builder.Done(fileMarker, GherkinNodeTypes.FILE, _sourceFile.Name);42 var resultTree = (GherkinFile) builder.BuildTree();43 return resultTree;44 }45 }46 private static void ParseTags(PsiBuilder builder)47 {48 while (builder.GetTokenType() == GherkinTokenTypes.TAG)49 {50 var tagMarker = builder.Mark();51 builder.AdvanceLexer();52 builder.Done(tagMarker, GherkinNodeTypes.TAG, null);53 if (builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)54 builder.AdvanceLexer();55 }56 }57 private static void ParseFeature(PsiBuilder builder)58 {59 var featureMarker = builder.Mark();60 Assertion.Assert(builder.GetTokenType() == GherkinTokenTypes.FEATURE_KEYWORD,61 "_builder.GetTokenType() == GherkinTokenTypes.FEATURE_KEYWORD");62 int? descMarker = null;63 bool wasLineBreak = false;64 do65 {66 builder.AdvanceLexer();67 var tokenType = builder.GetTokenType();68 if (tokenType == GherkinTokenTypes.TEXT && descMarker == null)69 {70 if (wasLineBreak)71 descMarker = builder.Mark();72 }73 if (GherkinTokenTypes.SCENARIOS_KEYWORDS[tokenType] ||74 tokenType == GherkinTokenTypes.RULE_KEYWORD ||75 tokenType == GherkinTokenTypes.BACKGROUND_KEYWORD ||76 tokenType == GherkinTokenTypes.TAG)77 {78 if (descMarker != null)79 {80 builder.Done(descMarker.Value, GherkinNodeTypes.FEATURE_HEADER, null);81 descMarker = null;82 }83 ParseFeatureElements(builder);84 }85 wasLineBreak = IsLineBreak(builder);86 } while (builder.GetTokenType() != GherkinTokenTypes.FEATURE_KEYWORD && !builder.Eof());87 if (descMarker != null)88 builder.Done(descMarker.Value, GherkinNodeTypes.FEATURE_HEADER, null);89 builder.Done(featureMarker, GherkinNodeTypes.FEATURE, null);90 }91 private static void ParseFeatureElements(PsiBuilder builder)92 {93 int? ruleMarker = null;94 while (builder.GetTokenType() != GherkinTokenTypes.FEATURE_KEYWORD && !builder.Eof())95 {96 if (builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)97 {98 builder.AdvanceLexer();99 continue;100 }101 ruleMarker = ParseRule(builder, ruleMarker);102 ParseScenario(builder);103 }104 if (ruleMarker.HasValue)105 builder.Done(ruleMarker.Value, GherkinNodeTypes.RULE, null);106 }107 private static int? ParseRule(PsiBuilder builder, int? ruleMarker)108 {109 if (builder.GetTokenType() == GherkinTokenTypes.RULE_KEYWORD)110 {111 if (ruleMarker != null)112 builder.Done(ruleMarker.Value, GherkinNodeTypes.RULE, null);113 ruleMarker = builder.Mark();114 builder.AdvanceLexer();115 if (builder.GetTokenType() == GherkinTokenTypes.COLON)116 builder.AdvanceLexer();117 else118 return ruleMarker;119 while (builder.GetTokenType() == GherkinTokenTypes.TEXT ||120 builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)121 builder.AdvanceLexer();122 }123 return ruleMarker;124 }125 private static void ParseScenario(PsiBuilder builder)126 {127 var scenarioMarker = builder.Mark();128 ParseTags(builder);129 // scenarios130 var startTokenType = builder.GetTokenType();131 var outline = startTokenType == GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD;132 builder.AdvanceLexer();133 while (!AtScenarioEnd(builder))134 {135 ParseTags(builder);136 if (ParseStepParameter(builder))137 continue;138 if (builder.GetTokenType() == GherkinTokenTypes.STEP_KEYWORD)139 ParseStep(builder);140 else if (builder.GetTokenType() == GherkinTokenTypes.EXAMPLES_KEYWORD)141 ParseExamplesBlock(builder);142 else143 builder.AdvanceLexer();144 }145 builder.Done(scenarioMarker, outline ? GherkinNodeTypes.SCENARIO_OUTLINE : GherkinNodeTypes.SCENARIO, null);146 }147 private static void ParseStep(PsiBuilder builder)148 {149 var marker = builder.Mark();150 builder.AdvanceLexer();151 while (builder.GetTokenType() == GherkinTokenTypes.TEXT ||152 builder.GetTokenType() == GherkinTokenTypes.STEP_PARAMETER_BRACE ||153 builder.GetTokenType() == GherkinTokenTypes.STEP_PARAMETER_TEXT ||154 builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)155 {156 if (IsLineBreak(builder))157 break;158 if (!ParseStepParameter(builder))159 builder.AdvanceLexer();160 }161 var nextToken = builder.GetTokenType(1);162 if (nextToken == GherkinTokenTypes.PIPE)163 {164 builder.AdvanceLexer();165 ParseTable(builder);166 }167 else if (nextToken == GherkinTokenTypes.PYSTRING)168 {169 builder.AdvanceLexer();170 ParsePystring(builder);171 }172 builder.Done(marker, GherkinNodeTypes.STEP, null);173 }174 private static void ParseExamplesBlock(PsiBuilder builder)175 {176 var marker = builder.Mark();177 builder.AdvanceLexer();178 if (builder.GetTokenType() == GherkinTokenTypes.COLON)179 builder.AdvanceLexer();180 while (builder.GetTokenType() == GherkinTokenTypes.TEXT ||181 builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)182 builder.AdvanceLexer();183 if (builder.GetTokenType() == GherkinTokenTypes.PIPE)184 ParseTable(builder);185 builder.Done(marker, GherkinNodeTypes.EXAMPLES_BLOCK, null);186 }187 private static void ParseTable(PsiBuilder builder)188 {189 var marker = builder.Mark();190 var rowMarker = builder.Mark();191 var headerNodeType = GherkinNodeTypes.TABLE_HEADER_ROW;192 int? cellMarker = null;193 var wasLineBreak = false;194 var possibleEmptyCell = false;195 while (builder.GetTokenType() == GherkinTokenTypes.PIPE ||196 builder.GetTokenType() == GherkinTokenTypes.TABLE_CELL ||197 builder.GetTokenType() == GherkinTokenTypes.WHITE_SPACE)198 {199 var tokenType = builder.GetTokenType();200 if (tokenType == GherkinTokenTypes.TABLE_CELL && cellMarker == null)201 {202 cellMarker = builder.Mark();203 }204 else if (tokenType != GherkinTokenTypes.TABLE_CELL && cellMarker != null)205 {206 builder.Done(cellMarker.Value, GherkinNodeTypes.TABLE_CELL, null);207 cellMarker = null;208 possibleEmptyCell = false;209 }210 if (tokenType == GherkinTokenTypes.PIPE)211 {212 if (wasLineBreak)213 {214 possibleEmptyCell = true;215 builder.Done(rowMarker, headerNodeType, null);216 headerNodeType = GherkinNodeTypes.TABLE_ROW;217 rowMarker = builder.Mark();218 }219 else220 {221 if (possibleEmptyCell)222 {223 cellMarker = builder.Mark();224 builder.Done(cellMarker.Value, GherkinNodeTypes.TABLE_CELL, null);225 cellMarker = null;226 }227 possibleEmptyCell = true;228 }229 }230 wasLineBreak = IsLineBreak(builder);231 builder.AdvanceLexer();232 }233 if (cellMarker.HasValue)234 builder.Done(cellMarker.Value, GherkinNodeTypes.TABLE_CELL, null);235 builder.Done(rowMarker, headerNodeType, null);236 builder.Done(marker, GherkinNodeTypes.TABLE, null);237 }238 private static void ParsePystring(PsiBuilder builder)239 {240 if (!builder.Eof())241 {242 var marker = builder.Mark();243 builder.AdvanceLexer();244 while (!builder.Eof() && builder.GetTokenType() != GherkinTokenTypes.PYSTRING)245 {246 if (!ParseStepParameter(builder))247 builder.AdvanceLexer();248 }249 if (!builder.Eof())250 builder.AdvanceLexer();251 builder.Done(marker, GherkinNodeTypes.PYSTRING, null);252 }253 }254 private static bool ParseStepParameter(PsiBuilder builder)255 {256 if (builder.GetTokenType() != GherkinTokenTypes.STEP_PARAMETER_TEXT)257 return false;258 var stepParameterMarker = builder.Mark();259 builder.AdvanceLexer();260 builder.Done(stepParameterMarker, GherkinNodeTypes.STEP_PARAMETER, null);261 return true;262 }263 private static bool AtScenarioEnd(PsiBuilder builder)264 {265 var i = 0;266 while (builder.GetTokenType(i) == GherkinTokenTypes.TAG ||267 builder.GetTokenType(i) == GherkinTokenTypes.WHITE_SPACE)268 i++;269 var tokenType = builder.GetTokenType(i);270 return tokenType == null || SCENARIO_END_TOKENS[tokenType];271 }272 private static bool IsLineBreak(PsiBuilder builder)273 {274 if (builder.GetTokenType() != GherkinTokenTypes.WHITE_SPACE)275 return false;276 return builder.GetTokenText()?.Contains("\n") == true;277 }278 }279}...
GherkinStepTaggerSpec.cs
Source:GherkinStepTaggerSpec.cs
...13 public void Should_tag_feature_with_title()14 {15 var gherkinStepTagger = new GherkinStepTagger();16 var line = new LineInFile(0);17 var evt = new GherkinParseEvent(GherkinTokenType.Feature,18 new Token("Feature", line), new Token("title", line), new Token("foo", line));19 ITextSnapshot snapshot = new MockTextSnapshot("Feature: title");20 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);21 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();22 Assert.AreEqual(GherkinTokenType.Feature, tags[0].Tag.Type);23 Assert.AreEqual("Feature", tags[0].Span.GetText());24 Assert.AreEqual(GherkinTokenType.FeatureTitle, tags[1].Tag.Type);25 Assert.AreEqual("title", tags[1].Span.GetText());26 }27 [Test]28 public void Should_tag_feature_narrative()29 {30 var gherkinStepTagger = new GherkinStepTagger();31 var line = new LineInFile(0);32 var evt = new GherkinParseEvent(GherkinTokenType.Feature,33 new Token("Feature", line), new Token("title", line), new Token("foo", line));34 ITextSnapshot snapshot = new MockTextSnapshot("foo");35 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);36 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();37 Assert.AreEqual(GherkinTokenType.FeatureDescription, tags[0].Tag.Type);38 Assert.AreEqual("foo", tags[0].Span.GetText());39 }40 [Test]41 public void Should_tag_feature_narrative_spanning_multiple_lines()42 {43 var gherkinStepTagger = new GherkinStepTagger();44 var line = new LineInFile(0);45 var evt = new GherkinParseEvent(GherkinTokenType.Feature,46 new Token("Feature", line), new Token("title", line), new Token("foo\r\n\tbar", line));47 ITextSnapshot snapshot = new MockTextSnapshot("\tbar\r\n");48 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);49 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();50 Assert.AreEqual(GherkinTokenType.FeatureDescription, tags[0].Tag.Type);51 Assert.AreEqual("bar", tags[0].Span.GetText());52 }53 [Test]54 public void Should_tag_scenario_with_title()55 {56 var gherkinStepTagger = new GherkinStepTagger();57 var line = new LineInFile(0);58 var evt = new GherkinParseEvent(GherkinTokenType.Scenario, new Token("Scenario", line), new Token("title", line));59 ITextSnapshot snapshot = new MockTextSnapshot("Scenario: title");60 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);61 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();62 Assert.AreEqual(GherkinTokenType.Scenario, tags[0].Tag.Type);63 Assert.AreEqual("Scenario", tags[0].Span.GetText());64 Assert.AreEqual(GherkinTokenType.ScenarioTitle, tags[1].Tag.Type);65 Assert.AreEqual("title", tags[1].Span.GetText());66 }67 [Test]68 public void Should_tag_scenario_with_title_spanning_multiple_lines()69 {70 var gherkinStepTagger = new GherkinStepTagger();71 var line = new LineInFile(0);72 var evt = new GherkinParseEvent(GherkinTokenType.Scenario, new Token("Scenario", line), new Token("title\n\tbar", line));73 ITextSnapshot snapshot = new MockTextSnapshot("bar");74 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);75 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();76 Assert.AreEqual(GherkinTokenType.ScenarioTitle, tags[0].Tag.Type);77 Assert.AreEqual("bar", tags[0].Span.GetText());78 }79 [Test]80 public void Should_tag_tags()81 {82 var gherkinStepTagger = new GherkinStepTagger();83 var line = new LineInFile(0);84 var evt = new GherkinParseEvent(GherkinTokenType.Tag, new Token("Tag", line), new Token("@foo", line), new Token("@bar", line), new Token("@baz", line));85 ITextSnapshot snapshot = new MockTextSnapshot("@foo @bar @baz");86 var span = new SnapshotSpan(snapshot, 0, snapshot.Length);87 var tags = gherkinStepTagger.CreateTags(new[] { evt }, span).ToArray();88 Assert.AreEqual(GherkinTokenType.Tag, tags[0].Tag.Type);89 Assert.AreEqual("@foo", tags[0].Span.GetText());90 Assert.AreEqual(GherkinTokenType.Tag, tags[1].Tag.Type);91 Assert.AreEqual("@bar", tags[1].Span.GetText());92 Assert.AreEqual(GherkinTokenType.Tag, tags[2].Tag.Type);93 Assert.AreEqual("@baz", tags[2].Span.GetText());94 }95 }96}...
GherkinClassifier.cs
Source:GherkinClassifier.cs
...8namespace NBehave.VS2012.Plugin.Editor.Domain9{10 public class GherkinClassifier : ITagger<ClassificationTag>11 {12 private readonly Dictionary<GherkinTokenType, IClassificationType> gherkinTypes;13 private readonly ITagAggregator<GherkinTokenTag> aggregator;14 private readonly Queue<IMappingSpan> tagsChanged = new Queue<IMappingSpan>();15 public GherkinClassifier(ITagAggregator<GherkinTokenTag> aggregator,16 IClassificationTypeRegistryService typeService)17 {18 this.aggregator = aggregator;19 aggregator.TagsChanged += TagsChangedOnAggregator;20 gherkinTypes = new Dictionary<GherkinTokenType, IClassificationType>();21 gherkinTypes[GherkinTokenType.SyntaxError] = typeService.GetClassificationType("gherkin.syntaxError");22 gherkinTypes[GherkinTokenType.Feature] = typeService.GetClassificationType("gherkin.feature");23 gherkinTypes[GherkinTokenType.FeatureTitle] = typeService.GetClassificationType("gherkin.featureTitle");24 gherkinTypes[GherkinTokenType.FeatureDescription] = typeService.GetClassificationType("gherkin.featureDescription");25 gherkinTypes[GherkinTokenType.Scenario] = typeService.GetClassificationType("gherkin.scenario");26 gherkinTypes[GherkinTokenType.ScenarioTitle] = typeService.GetClassificationType("gherkin.scenarioTitle");27 gherkinTypes[GherkinTokenType.Background] = typeService.GetClassificationType("gherkin.background");28 gherkinTypes[GherkinTokenType.BackgroundTitle] = typeService.GetClassificationType("gherkin.backgroundTitle");29 gherkinTypes[GherkinTokenType.Comment] = typeService.GetClassificationType("gherkin.comment");30 gherkinTypes[GherkinTokenType.Tag] = typeService.GetClassificationType("gherkin.tag");31 gherkinTypes[GherkinTokenType.DocString] = typeService.GetClassificationType("gherkin.docstring");32 gherkinTypes[GherkinTokenType.Examples] = typeService.GetClassificationType("gherkin.examples");33 gherkinTypes[GherkinTokenType.Step] = typeService.GetClassificationType("gherkin.step");34 gherkinTypes[GherkinTokenType.StepText] = typeService.GetClassificationType("gherkin.stepText");35 gherkinTypes[GherkinTokenType.Table] = typeService.GetClassificationType("gherkin.table");36 gherkinTypes[GherkinTokenType.TableHeader] = typeService.GetClassificationType("gherkin.tableheader");37 gherkinTypes[GherkinTokenType.TableCell] = typeService.GetClassificationType("gherkin.tablecell");38 gherkinTypes[GherkinTokenType.TableCellAlt] = typeService.GetClassificationType("gherkin.tablecellalt");39 }40 private void TagsChangedOnAggregator(object sender, TagsChangedEventArgs e)41 {42 tagsChanged.Enqueue(e.Span);43 NotifyTagChanged(e.Span.AnchorBuffer.CurrentSnapshot);44 }45 public IEnumerable<ITagSpan<ClassificationTag>> GetTags(NormalizedSnapshotSpanCollection spans)46 {47 var tags = aggregator.GetTags(spans).ToList();48 foreach (var tagSpan in tags)49 yield return CreateTagSpanForTag(spans[0].Snapshot, tagSpan);50 NotifyTagsChanged(spans);51 }52 private void NotifyTagsChanged(NormalizedSnapshotSpanCollection spans)53 {54 while (tagsChanged.Any())55 NotifyTagChanged(spans[0].Snapshot);56 }57 private void NotifyTagChanged(ITextSnapshot snapshot)58 {59 IMappingSpan t = tagsChanged.Dequeue();60 NormalizedSnapshotSpanCollection sp = t.GetSpans(snapshot);61 if (TagsChanged != null)62 TagsChanged.Invoke(this, new SnapshotSpanEventArgs(sp.First()));63 }64 private ITagSpan<ClassificationTag> CreateTagSpanForTag(ITextSnapshot snapShot, IMappingTagSpan<GherkinTokenTag> tagSpan)65 {66 NormalizedSnapshotSpanCollection tagSpans = tagSpan.Span.GetSpans(snapShot);67 GherkinTokenType classificationType = tagSpan.Tag.Type;68 return new TagSpan<ClassificationTag>(tagSpans[0], new ClassificationTag(gherkinTypes[classificationType]));69 }70 public event EventHandler<SnapshotSpanEventArgs> TagsChanged;71 }72}
GherkinKeywordList.cs
Source:GherkinKeywordList.cs
...10 public class GherkinKeywordList11 {12 // i18n.json file contains list of keywords and some meta-information about the language. At the moment it's three attributes below. 13 private static readonly string[] GherkinLanguageMetaAttributes = {"name", "native", "encoding"};14 private static readonly Dictionary<string, GherkinTokenType> TokenTypes =15 new Dictionary<string, GherkinTokenType>16 {17 {"Feature", GherkinTokenTypes.FEATURE_KEYWORD},18 {"Background", GherkinTokenTypes.BACKGROUND_KEYWORD},19 {"Scenario", GherkinTokenTypes.SCENARIO_KEYWORD},20 {"Rule", GherkinTokenTypes.RULE_KEYWORD},21 {"Example", GherkinTokenTypes.EXAMPLE_KEYWORD},22 {"Scenario Outline", GherkinTokenTypes.SCENARIO_OUTLINE_KEYWORD},23 {"Examples", GherkinTokenTypes.EXAMPLES_KEYWORD},24 {"Scenarios", GherkinTokenTypes.EXAMPLES_KEYWORD},25 {"Given", GherkinTokenTypes.STEP_KEYWORD},26 {"When", GherkinTokenTypes.STEP_KEYWORD},27 {"Then", GherkinTokenTypes.STEP_KEYWORD},28 {"And", GherkinTokenTypes.STEP_KEYWORD},29 {"But", GherkinTokenTypes.STEP_KEYWORD},30 {"*", GherkinTokenTypes.STEP_KEYWORD}31 };32 private readonly HashSet<string> _spaceAfterKeywords = new HashSet<string>();33 private readonly Dictionary<string, string> _translatedKeywords = new Dictionary<string, string>();34 private readonly Dictionary<string, GherkinTokenType> _translatedTokenTypes = new Dictionary<string, GherkinTokenType>();35 // Need to use Descending comparer, because long keywords should be first.36 // For example: "Scenario" keyword is a part of "Scenario Outline" keyword.37 private readonly SortedSet<string> _allKeywords = new SortedSet<string>(new DescendingComparer<string>());38 public GherkinKeywordList(JObject keywords)39 {40 foreach (var (key, values) in keywords)41 {42 if (GherkinLanguageMetaAttributes.Contains(key))43 continue;44 var keyword = CapitalizeAndFixSpace(key);45 var tokenType = TokenTypes[keyword];46 foreach (var jToken in values)47 {48 var translatedKeyword = jToken.Value<string>();49 if (translatedKeyword.EndsWith(" "))50 {51 translatedKeyword = translatedKeyword.Substring(0, translatedKeyword.Length - 1);52 _spaceAfterKeywords.Add(translatedKeyword);53 }54 55 _translatedKeywords[translatedKeyword] = keyword;56 _translatedTokenTypes[translatedKeyword] = tokenType;57 _allKeywords.Add(translatedKeyword);58 }59 }60 }61 private static string CapitalizeAndFixSpace(string keyword)62 {63 var result = new StringBuilder();64 for (var i = 0; i < keyword.Length; i++)65 {66 var c = keyword[i];67 if (i == 0)68 c = char.ToUpper(c);69 if (char.IsUpper(c) && i > 0)70 result.Append(' ');71 result.Append(c);72 }73 return result.ToString();74 }75 public IReadOnlyCollection<string> GetAllKeywords()76 {77 return _allKeywords;78 }79 80 public bool IsSpaceRequiredAfterKeyword(string keyword)81 {82 return _spaceAfterKeywords.Contains(keyword);83 }84 public TokenNodeType GetTokenType(string keyword)85 {86 return _translatedTokenTypes[keyword];87 }88 private class DescendingComparer<T> : IComparer<T> where T : IComparable<T>89 {90 public int Compare(T x, T y)91 {92 return y.CompareTo(x);93 }94 }95 }96}...
GherkinEventListener.cs
Source:GherkinEventListener.cs
...9 public List<GherkinParseEvent> Events10 {11 get { return events; }12 }13 public void Feature(Token keyword, Token title, Token narrative)14 {15 events.Add(new GherkinParseEvent(GherkinTokenType.Feature, keyword, title, narrative));16 }17 public void Scenario(Token keyword, Token title)18 {19 events.Add(new GherkinParseEvent(GherkinTokenType.Scenario, keyword, title));20 }21 public void Examples(Token keyword, Token name)22 {23 events.Add(new GherkinParseEvent(GherkinTokenType.Examples, keyword, name));24 }25 public void Step(Token keyword, Token name)26 {27 events.Add(new GherkinParseEvent(GherkinTokenType.Step, keyword, name));28 }29 public void Table(IList<IList<Token>> rows, LineInFile lineInFile)30 {31 if (rows.Any())32 {33 var header = rows.First();34 events.Add(new GherkinParseEvent(GherkinTokenType.TableHeader, new Token(string.Join(" | ", header).Trim(), lineInFile)));35 var cells = rows.Skip(1);36 var cellLine = lineInFile;37 foreach (var cell in cells)38 {39 cellLine = new LineInFile(cellLine.Line + 1);40 events.Add(new GherkinParseEvent(GherkinTokenType.TableCell, new Token(string.Join(" | ", cell).Trim(), cellLine)));41 }42 }43 }44 public void Background(Token keyword, Token name)45 {46 events.Add(new GherkinParseEvent(GherkinTokenType.Background, keyword, name));47 }48 public void Comment(Token comment)49 {50 events.Add(new GherkinParseEvent(GherkinTokenType.Comment, comment));51 }52 public void Tag(Token tag)53 {54 if (tag.Content != "@") //bug in gherkin parser?55 {56 var previous = events.LastOrDefault() ?? new GherkinParseEvent(GherkinTokenType.SyntaxError);57 if (previous.GherkinTokenType == GherkinTokenType.Tag && tag.LineInFile.Line == previous.Tokens[0].LineInFile.Line)58 previous.Tokens.Add(tag);59 else60 events.Add(new GherkinParseEvent(GherkinTokenType.Tag, tag));61 }62 }63 public void SyntaxError(string state, string @event, IEnumerable<string> legalEvents, LineInFile lineInFile)64 {65 events.Add(new GherkinParseEvent(GherkinTokenType.SyntaxError, new Token(@event, lineInFile)));66 }67 public void Eof()68 {69 events.Add(new GherkinParseEvent(GherkinTokenType.Eof));70 }71 public void DocString(Token docString)72 {73 events.Add(new GherkinParseEvent(GherkinTokenType.DocString, docString));74 }75 }76}...
GherkinTokenTypes.cs
Source:GherkinTokenTypes.cs
1using JetBrains.ReSharper.Psi.ExtensionsAPI.Tree;2// ReSharper disable InconsistentNaming3namespace ReSharperPlugin.SpecflowRiderPlugin.Psi4{5 public static class GherkinTokenTypes6 {7 public static readonly GherkinTokenType WHITE_SPACE = new GherkinTokenType("WHITE_SPACE", 1001);8 public static readonly GherkinTokenType COMMENT = new GherkinTokenType("COMMENT", 1002);9 public static readonly GherkinTokenType TEXT = new GherkinTokenType("TEXT", 1003);10 public static readonly GherkinTokenType EXAMPLES_KEYWORD = new GherkinTokenType("EXAMPLES_KEYWORD", 1004);11 public static readonly GherkinTokenType FEATURE_KEYWORD = new GherkinTokenType("FEATURE_KEYWORD", 1005);12 public static readonly GherkinTokenType RULE_KEYWORD = new GherkinTokenType("RULE_KEYWORD", 1006);13 public static readonly GherkinTokenType BACKGROUND_KEYWORD = new GherkinTokenType("BACKGROUND_KEYWORD", 1007);14 public static readonly GherkinTokenType SCENARIO_KEYWORD = new GherkinTokenType("SCENARIO_KEYWORD", 1008);15 public static readonly GherkinTokenType EXAMPLE_KEYWORD = new GherkinTokenType("EXAMPLE_KEYWORD", 1009);16 public static readonly GherkinTokenType SCENARIO_OUTLINE_KEYWORD = new GherkinTokenType("SCENARIO_OUTLINE_KEYWORD", 1010);17 public static readonly GherkinTokenType STEP_KEYWORD = new GherkinTokenType("STEP_KEYWORD", 1011);18 public static readonly GherkinTokenType STEP_PARAMETER_BRACE = new GherkinTokenType("STEP_PARAMETER_BRACE", 1012);19 public static readonly GherkinTokenType STEP_PARAMETER_TEXT = new GherkinTokenType("STEP_PARAMETER_TEXT", 1013);20 public static readonly GherkinTokenType COLON = new GherkinTokenType("COLON", 1014);21 public static readonly GherkinTokenType TAG = new GherkinTokenType("TAG", 1015);22 public static readonly GherkinTokenType PYSTRING = new GherkinTokenType("PYSTRING_QUOTES", 1016);23 public static readonly GherkinTokenType PYSTRING_TEXT = new GherkinTokenType("PYSTRING_TEXT", 1017);24 public static readonly GherkinTokenType PIPE = new GherkinTokenType("PIPE", 1018);25 public static readonly GherkinTokenType TABLE_CELL = new GherkinTokenType("TABLE_CELL", 1019);26 public static readonly NodeTypeSet KEYWORDS = new NodeTypeSet(FEATURE_KEYWORD, RULE_KEYWORD, EXAMPLE_KEYWORD,27 BACKGROUND_KEYWORD, SCENARIO_KEYWORD, SCENARIO_OUTLINE_KEYWORD,28 EXAMPLES_KEYWORD, EXAMPLES_KEYWORD,29 STEP_KEYWORD);30 public static readonly NodeTypeSet SCENARIOS_KEYWORDS = new NodeTypeSet(SCENARIO_KEYWORD, SCENARIO_OUTLINE_KEYWORD, EXAMPLE_KEYWORD);31 }32}...
GherkinSyntaxHighlightingProcessor.cs
Source:GherkinSyntaxHighlightingProcessor.cs
...19 return false;20 }21 return base.InteriorShouldBeProcessed(element, context);22 }23 public override string GetAttributeId(TokenNodeType tokenType)24 {25 if (tokenType == GherkinTokenTypes.TAG)26 return GherkinHighlightingAttributeIds.TAG;27 28 if (tokenType == GherkinTokenTypes.STEP_PARAMETER_TEXT)29 return GherkinHighlightingAttributeIds.OUTLINE_PARAMETER_SUBSTITUTION;30 if (tokenType == GherkinTokenTypes.TEXT)31 return GherkinHighlightingAttributeIds.TEXT;32 if (tokenType == GherkinTokenTypes.TABLE_CELL)33 return GherkinHighlightingAttributeIds.TABLE_CELL;34 if (tokenType == GherkinTokenTypes.STEP_PARAMETER_TEXT) //TODO Detect regex parameter like: "param"35 return GherkinHighlightingAttributeIds.REGEXP_PARAMETER;36 if (tokenType == GherkinTokenTypes.PIPE)37 return GherkinHighlightingAttributeIds.PIPE;38 return base.GetAttributeId(tokenType);39 }40 protected override bool IsLineComment(TokenNodeType tokenType)41 {42 return tokenType == GherkinTokenTypes.COMMENT;43 }44 protected override bool IsKeyword(TokenNodeType tokenType)45 {46 return GherkinTokenTypes.KEYWORDS[tokenType];47 }48 protected override bool IsString(TokenNodeType tokenType)49 {50 return tokenType == GherkinTokenTypes.PYSTRING;51 }52 protected override string KeywordAttributeId => GherkinHighlightingAttributeIds.KEYWORD;53 protected override string LineCommentAttributeId => GherkinHighlightingAttributeIds.LINE_COMMENT;54 55 protected override string StringAttributeId => GherkinHighlightingAttributeIds.PYSTRING;56 }57}...
Token
Using AI Code Generation
1using Gherkin;2using Gherkin.Ast;3using Gherkin.Parser;4using Gherkin.Pickles;5using Gherkin.Pickles.Compiler;6using Gherkin.Pickles.Pickles;7using Gherkin.Pickles.Pickles.Pickles;8using Gherkin.Query;9using Gherkin.Query.Pickles;10using Gherkin.Query.Pickles.Pickles;11using Gherkin.Query.Pickles.Pickles.Pickles;12using Gherkin.Query.Pickles.Pickles.Pickles.Pickles;13using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles;14using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles;15using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles;16using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles;17using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles;18using Gherkin.Query.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles.Pickles;
Token
Using AI Code Generation
1using Gherkin.Ast;2using Gherkin.Parser;3using Gherkin.TokenMatcher;4using Gherkin.TokenScanner;5{6 {7 private readonly TokenMatcher _matcher;8 private readonly TokenScanner _scanner;9 private readonly TokenQueue _tokenQueue;10 public Parser()11 {12 _scanner = new TokenScanner();13 _matcher = new TokenMatcher();14 _tokenQueue = new TokenQueue();15 }16 public GherkinDocument Parse(string feature)17 {18 _scanner.Scan(feature);19 _tokenQueue.Enqueue(_scanner.Tokens);20 var gherkinDocument = new GherkinDocument();21 var featureNode = new Feature();22 gherkinDocument.Feature = featureNode;23 Match(TokenType.Feature, featureNode);24 Match(TokenType.Colon, featureNode);25 Match(TokenType.Text, featureNode);26 Match(TokenType.NewLine, featureNode);27 Match(TokenType.Text, featureNode);
Token
Using AI Code Generation
1using System;2using System.IO;3using Gherkin;4{5 {6 static void Main(string[] args)7 {8 string path = @"C:\Users\username\Documents\Visual Studio 2015\Projects\GherkinTest\GherkinTest\GherkinTest\GherkinTest\Feature1.feature";9 string feature = File.ReadAllText(path);10 TokenScanner scanner = new TokenScanner(feature);11 Token token = scanner.NextToken();12 while (token != null)13 {14 Console.WriteLine(token.Line + " " + token.Column + " " + token.TokenValue);15 token = scanner.NextToken();16 }17 Console.ReadLine();18 }19 }20}
Token
Using AI Code Generation
1using Gherkin.Ast;2using Gherkin;3using System.IO;4using System.Collections.Generic;5using System.Linq;6{7 {8 static void Main(string[] args)9 {10 var parser = new Parser();11 var lexer = new Lexer();12 var featureText = File.ReadAllText("C:\\Users\\user\\Desktop\\GherkinTest\\GherkinTest\\Features\\1.feature");13 var tokens = lexer.Scan(featureText);14 var feature = parser.Parse(tokens);15 foreach (var scenario in feature.Children)16 {17 Console.WriteLine(scenario.ToString());18 }19 Console.ReadLine();20 }21 }22}
Token
Using AI Code Generation
1using Gherkin;2using TechTalk.SpecFlow;3{4 {5 [Given(@"I have a number (.*)")]6 public void GivenIHaveANumber(Token number)7 {8 ScenarioContext.Current["number"] = number;9 }10 }11}12[Given(@"I have a number (.*)")]13public void GivenIHaveANumber(int number)14{15 ScenarioContext.Current["number"] = number;16}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!