Beispiel #1
0
        public bool Equals(GherkinParseEvent obj)
        {
            if (obj == null)
                return false;
            if (ReferenceEquals(this, obj)) return true;
            if (obj.GetType() != GetType()) return false;

            return obj.GherkinTokenType == GherkinTokenType
                &&  TokensAreEqual(obj);
        }
Beispiel #2
0
 private bool TokensAreEqual(GherkinParseEvent other)
 {
     if (other.Tokens.Count != Tokens.Count)
         return false;
     for (int i = 0; i < Tokens.Count; i++)
     {
         if (Tokens[i] != other.Tokens[i])
             return false;
     }
     return true;
 }
Beispiel #3
0
 private void NotifyChanges(ITextSnapshot textSnapshot, IEnumerable<GherkinParseEvent> newAndChanged)
 {
     var linesChanged = newAndChanged
         .Where(_ => _.Tokens.Any())
         .Select(_ => _.Tokens[0].LineInFile.Line)
         .Distinct().ToArray();
     int from = linesChanged.Min();
     int to = linesChanged.Max();
     var previousEvent = new GherkinParseEvent(GherkinTokenType.Feature, new Token("", new LineInFile(0)));
     for (int i = from; i <= to; i++)
     {
         ITextSnapshotLine line = textSnapshot.GetLineFromLineNumber(i);
         var s = new SnapshotSpan(textSnapshot, line.Start, line.Length);
         GherkinParseEvent evt = newAndChanged.FirstOrDefault(_ => _.Tokens.Any() && _.Tokens[0].LineInFile.Line == i) ??
             new GherkinParseEvent(previousEvent.GherkinTokenType, new Token("", new LineInFile(i)));
         TokenParserEvent.Invoke(this, new TokenParserEventArgs(evt, s));
         previousEvent = evt;
     }
     var lastLine = textSnapshot.GetLineFromLineNumber(to);
     TokenParserEvent.Invoke(this, new TokenParserEventArgs(new GherkinParseEvent(GherkinTokenType.Eof), new SnapshotSpan(textSnapshot, lastLine.Start, 0)));
 }
Beispiel #4
0
 private Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>> CreateTag(Token token, SnapshotSpan span, GherkinParseEvent evt)
 {
     var text = span.GetText();
     return CreateTag(token, span, evt.GherkinTokenType, text);
 }
Beispiel #5
0
 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;
     }
 }
Beispiel #6
0
 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;
 }
Beispiel #7
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt, GherkinTokenType tokenType, GherkinTokenType tokenTitleType)
 {
     if (!evt.Tokens.Any())
         yield break;
     var t1 = HandleType(span, evt.Tokens.First(), tokenType);
     if (t1 != null) yield return t1;
     if (evt.Tokens.Count >= 2)
     {
         var t2 = HandleTitle(span, evt.Tokens[1], tokenTitleType);
         foreach (var tuple in t2)
             yield return tuple;
     }
 }
Beispiel #8
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTag(SnapshotSpan span, GherkinParseEvent evt)
 {
     var tags = new List<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>>();
     foreach (var token in evt.Tokens)
         tags.AddRange(HandleTitle(span, token, GherkinTokenType.Tag));
     return tags;
 }
Beispiel #9
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleBackground(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Background, GherkinTokenType.BackgroundTitle);
 }
Beispiel #10
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableCell(SnapshotSpan span, GherkinParseEvent evt)
 {
     var tokenType = cellToggle ? GherkinTokenType.TableCell : GherkinTokenType.TableCellAlt;
     cellToggle = !cellToggle;
     return TableItem(span, tokenType);
 }
Beispiel #11
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleStep(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Step, GherkinTokenType.StepText);
 }
Beispiel #12
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleSpan(SnapshotSpan span, GherkinParseEvent evt)
 {
     ITextSnapshotLine containingLine = span.Start.GetContainingLine();
     var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
     var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));
     yield return new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan);
 }
Beispiel #13
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleScenario(SnapshotSpan span, GherkinParseEvent evt)
 {
     return HandleTag(span, evt, GherkinTokenType.Scenario, GherkinTokenType.ScenarioTitle);
 }
Beispiel #14
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleFeature(SnapshotSpan span, GherkinParseEvent evt)
 {
     if (!evt.Tokens.Any())
         yield break;
     var t1 = HandleType(span, evt.Tokens.First(), GherkinTokenType.Feature);
     if (t1 != null) yield return t1;
     if (evt.Tokens.Count >= 2)
     {
         var t2 = HandleTitle(span, evt.Tokens[1], GherkinTokenType.FeatureTitle);
         foreach (var tuple in t2)
             yield return tuple;
     }
     if (evt.Tokens.Count == 3)
     {
         var t3 = HandleTitle(span, evt.Tokens[2], GherkinTokenType.FeatureDescription);
         foreach (var tuple in t3)
             yield return tuple;
     }
 }
Beispiel #15
0
        private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleDocString(SnapshotSpan span, GherkinParseEvent evt)
        {
            var text = span.GetText().Trim(WhiteSpaces.Chars);
            if (text == "\"\"\"")
                return HandleText(span, GherkinTokenType.Tag, "\"");

            //TODO: dont color the spaces that will be removed
            ITextSnapshotLine containingLine = span.Start.GetContainingLine();
            var tokenSpan = new SnapshotSpan(span.Snapshot, new Span(containingLine.Start.Position, containingLine.Length));
            var tagSpan = new TagSpan<GherkinTokenTag>(tokenSpan, new GherkinTokenTag(evt.GherkinTokenType));
            return new[] { new Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>(tokenSpan, tagSpan) };
        }
Beispiel #16
0
 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;
         }
     }
 }
Beispiel #17
0
 private IEnumerable<Tuple<SnapshotSpan, TagSpan<GherkinTokenTag>>> HandleTableHeader(SnapshotSpan span, GherkinParseEvent evt)
 {
     cellToggle = false;
     return TableItem(span, evt.GherkinTokenType);
 }
 public TokenParserEventArgs(GherkinParseEvent evt, SnapshotSpan snapshotSpan)
 {
     Event = evt;
     SnapshotSpan = snapshotSpan;
 }