Ejemplo n.º 1
0
        /// <summary>
        /// A parser that consumes the next <see cref="LexicalToken"/> (or series of adjacent tokens) if it has one of the specified texts, producing a single <see cref="SyntaxToken"/>.
        /// It does not show up in intellisense completion lists.
        /// </summary>
        public static Parser <LexicalToken, SyntaxToken> HiddenToken(IReadOnlyList <string> texts)
        {
            Ensure.ArgumentNotNull(texts, nameof(texts));
            var set = new HashSet <string>(texts);

            var rule = Match(t => set.Contains(t.Text), lt => SyntaxToken.From(lt)).WithTag(string.Join(" | ", texts.Select(t => GetDefaultTag(t))));

            return(rule);
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Create a <see cref="SyntaxToken"/> from one or more <see cref="LexicalToken"/>.
 /// </summary>
 private static SyntaxToken ProduceSyntaxToken(Source <LexicalToken> source, int start, int length, string text)
 {
     if (length == 1)
     {
         return(SyntaxToken.From(source.Peek(start)));
     }
     else
     {
         // use the trivia form the first token and the text supplied (instead of concatenating the same text from the tokens)
         return(SyntaxToken.Identifier(source.Peek(start).Trivia, text));
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// A parser that consumes the next next <see cref="LexicalToken"/> if it has the specified <see cref="SyntaxKind"/>, producing a corresponding <see cref="SyntaxToken"/>.
        /// </summary>
        public static Parser <LexicalToken, SyntaxToken> Token(SyntaxKind kind, CompletionItem item)
        {
            var rule = Match(t => t.Kind == kind, lt => SyntaxToken.From(lt)).WithTag(GetDefaultTag(kind));

            item = item ?? GetDefaultCompletionItem(kind, null, CompletionPriority.Normal, null);
            if (item != null)
            {
                rule = rule.WithAnnotations(new[] { item });
            }

            return(rule);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// A parser that consumes the next next <see cref="LexicalToken"/> if it has the specified <see cref="SyntaxKind"/>, producing a corresponding <see cref="SyntaxToken"/>.
        /// </summary>
        public static Parser <LexicalToken, SyntaxToken> Token(SyntaxKind kind, CompletionKind?ckind = null, CompletionPriority priority = CompletionPriority.Normal, string ctext = null)
        {
            var rule = Match(t => t.Kind == kind, lt => SyntaxToken.From(lt)).WithTag(GetDefaultTag(kind));

            var item = GetDefaultCompletionItem(kind, ckind, priority, ctext);

            if (item != null)
            {
                rule = rule.WithAnnotations(new[] { item });
            }

            return(rule);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// A parser that consumes the next <see cref="LexicalToken"/> (or series of adjacent tokens) if it has one of the specified texts, producing a single <see cref="SyntaxToken"/>.
        /// </summary>
        public static Parser <LexicalToken, SyntaxToken> Token(IReadOnlyList <string> texts, CompletionKind?ckind = null, CompletionPriority priority = CompletionPriority.Normal)
        {
            Ensure.ArgumentNotNull(texts, nameof(texts));
            var set = new HashSet <string>(texts);

            var rule = Match(t => set.Contains(t.Text), lt => SyntaxToken.From(lt)).WithTag(string.Join(" | ", texts.Select(t => GetDefaultTag(t))));

            var items = GetCompletionItems(texts, ckind, priority).ToList();

            if (items.Count > 0)
            {
                rule = rule.WithAnnotations(items);
            }

            return(rule);
        }
Ejemplo n.º 6
0
        public override string GetMinimalText(MinimalTextKind kind, CancellationToken cancellationToken)
        {
            // use kusto lexer to identify tokens and trivia (as best guess)
            var parser = new Parsing.TokenParser();
            var list   = new SyntaxList <SyntaxToken>(parser.ParseTokens(this.Text).Select(t => SyntaxToken.From(t)).ToArray());

            return(list.ToString(KustoCodeService.GetIncludeTrivia(kind)));
        }
        public override string GetMinimalText(CancellationToken cancellationToken)
        {
            // use kusto lexer to identify tokens and trivia (as best guess)
            var list = new SyntaxList <SyntaxToken>(Parsing.LexicalGrammar.GetTokens(this.Text).Select(t => SyntaxToken.From(t)).ToArray());

            return(list.ToString(IncludeTrivia.Minimal));
        }
Ejemplo n.º 8
0
 /// <summary>
 /// A parser that consumes the next next <see cref="LexicalToken"/> if it has the specified <see cref="SyntaxKind"/>, producing a corresponding <see cref="SyntaxToken"/>.
 /// It does not show up in intellisense completion lists.
 /// </summary>
 public static Parser <LexicalToken, SyntaxToken> HiddenToken(SyntaxKind tokenKind)
 {
     return(Match(t => t.Kind == tokenKind, lt => SyntaxToken.From(lt)).WithTag(GetDefaultTag(tokenKind)));
 }