public static void WriteKeyword(this TextWriter writer, SyntaxKind kind) { var text = SyntaxFacts.GetText(kind); Debug.Assert(kind.IsKeyword() && text != null); writer.WriteKeyword(text); }
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); } }
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); } }
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); }
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 });
public static bool IsToken(this SyntaxKind kind) { return(!kind.IsTrivia() && (kind.IsKeyword() || kind.ToString().EndsWith("Token"))); }
public static bool IsIdentifierOrKeyword(this SyntaxKind kind) { return(kind == SyntaxKind.IdentifierToken || kind.IsKeyword()); }
public static void IsKeyword(SyntaxKind kind, bool expectedResult) => Assert.That(kind.IsKeyword(), Is.EqualTo(expectedResult));