コード例 #1
0
        public static void WriteKeyword(this TextWriter writer, SyntaxKind kind)
        {
            var text = SyntaxFacts.GetText(kind);

            Debug.Assert(kind.IsKeyword() && text != null);
            writer.WriteKeyword(text);
        }
コード例 #2
0
        private static Classification GetClassification(SyntaxKind kind)
        {
            var isKeyword    = kind.IsKeyword();
            var isIdentifier = kind == SyntaxKind.IdentifierToken;
            var isNumber     = kind == SyntaxKind.NumberToken;
            var isString     = kind == SyntaxKind.StringToken;
            var isComment    = kind.IsComment();

            if (isKeyword)
            {
                return(Classification.Keyword);
            }
            else if (isIdentifier)
            {
                return(Classification.Identifier);
            }
            else if (isNumber)
            {
                return(Classification.Number);
            }
            else if (isString)
            {
                return(Classification.String);
            }
            else if (isComment)
            {
                return(Classification.Comment);
            }
            else
            {
                return(Classification.Text);
            }
        }
コード例 #3
0
 private static Classification GetClassification(SyntaxKind kind)
 {
     if (kind.IsKeyword())
     {
         return(Classification.Keyword);
     }
     else if (kind.IsPunctuation())
     {
         return(Classification.Punctuation);
     }
     else if (kind == SyntaxKind.Identifier)
     {
         return(Classification.Identifier);
     }
     else if (kind == SyntaxKind.NumericLiteral)
     {
         return(Classification.Number);
     }
     else if (kind == SyntaxKind.StringLiteral)
     {
         return(Classification.String);
     }
     else if (kind == SyntaxKind.CommentTrivia)
     {
         return(Classification.Comment);
     }
     else
     {
         return(Classification.Text);
     }
 }
コード例 #4
0
ファイル: LexerTests.cs プロジェクト: dallmair/nquery-vnext
        private static void LexPunctuationOrOperator(SyntaxKind kind)
        {
            var text  = kind.GetText();
            var token = SyntaxFacts.ParseToken(text);

            var expectedContextualKind = kind.IsKeyword()
                ? SyntaxKind.IdentifierToken
                : SyntaxKind.BadToken;

            Assert.Equal(kind, token.Kind);
            Assert.Equal(expectedContextualKind, token.ContextualKind);
            Assert.Equal(text, token.Text);
            Assert.False(token.IsMissing);
            Assert.True(token.IsTerminated());
            Assert.Empty(token.Diagnostics);
        }
コード例 #5
0
    private static Classification GetClassification(SyntaxKind tokenKind)
    {
        if (tokenKind.IsKeyword())
        {
            return(Classification.Keyword);
        }

        if (tokenKind.IsComment())
        {
            return(Classification.Comment);
        }

        return(tokenKind switch
        {
            SyntaxKind.IdentifierToken => Classification.Identifier,
            SyntaxKind.NumberToken => Classification.Number,
            SyntaxKind.StringToken => Classification.String,
            _ => Classification.Text
        });
コード例 #6
0
ファイル: SyntaxFacts.cs プロジェクト: stefan991/minsk
 public static bool IsToken(this SyntaxKind kind)
 {
     return(!kind.IsTrivia() &&
            (kind.IsKeyword() || kind.ToString().EndsWith("Token")));
 }
コード例 #7
0
ファイル: SyntaxFacts.cs プロジェクト: dallmair/nquery-vnext
 public static bool IsIdentifierOrKeyword(this SyntaxKind kind)
 {
     return(kind == SyntaxKind.IdentifierToken || kind.IsKeyword());
 }
コード例 #8
0
 public static void IsKeyword(SyntaxKind kind, bool expectedResult) =>
 Assert.That(kind.IsKeyword(), Is.EqualTo(expectedResult));