SyntaxToken Struct

A terminal of the grammar: the smallest piece of a tree that carries text.

public readonly struct SyntaxToken : IEquatable<SyntaxToken>

Remarks

A token is a view rather than an object of its own, so default is a valid, empty token rather than something that throws. Compare against SyntaxToken.None, or test SyntaxToken.RawKind, to detect it.

Implements

Properties

NameDescription
ContainsAnnotations
ContainsDiagnostics
ContainsSkippedText
FullSpanGets the range this token covers, including the trivia on both sides.
HasLeadingTrivia
HasTrailingTrivia
IsMissingGets a value indicating whether the parser inserted this token rather than reading it from the text.
LeadingTriviaGets the trivia that comes before this token's text.
NoneGets the token that is not there.
ParentGets the node this token is a child of.
RawKindGets the language-specific kind of this token as a plain integer.
SpanGets the range the token's own text covers.
SpanStart
TextGets the token exactly as it was spelled in the source.
TrailingTriviaGets the trivia that comes after this token's text.
ValueGets the decoded value of the token, which may be a number or another type the language chose.
ValueTextGets the value the text denotes, which is the text itself unless the language decoded something else.

ContainsAnnotations

SyntaxToken.cs
public bool ContainsAnnotations { get; }

Property value

bool

No documentation is available.

ContainsDiagnostics

SyntaxToken.cs
public bool ContainsDiagnostics { get; }

Property value

bool

No documentation is available.

ContainsSkippedText

SyntaxToken.cs
public bool ContainsSkippedText { get; }

Property value

bool

No documentation is available.

Gets the range this token covers, including the trivia on both sides.

public TextSpan FullSpan { get; }

Property value

TextSpan

HasLeadingTrivia

SyntaxToken.cs
public bool HasLeadingTrivia { get; }

Property value

bool

No documentation is available.

HasTrailingTrivia

SyntaxToken.cs
public bool HasTrailingTrivia { get; }

Property value

bool

No documentation is available.

Gets a value indicating whether the parser inserted this token rather than reading it from the text.

public bool IsMissing { get; }

Property value

bool

LeadingTrivia

SyntaxToken.cs

Gets the trivia that comes before this token's text.

public SyntaxTriviaList LeadingTrivia { get; }

Property value

SyntaxTriviaList

Gets the token that is not there.

public static SyntaxToken None { get; }

Property value

SyntaxToken

Gets the node this token is a child of.

public SyntaxNode? Parent { get; }

Property value

SyntaxNode?

Gets the language-specific kind of this token as a plain integer.

public int RawKind { get; }

Property value

int

Gets the range the token's own text covers.

public TextSpan Span { get; }

Property value

TextSpan

public int SpanStart { get; }

Property value

int

No documentation is available.

Gets the token exactly as it was spelled in the source.

public string Text { get; }

Property value

string

TrailingTrivia

SyntaxToken.cs

Gets the trivia that comes after this token's text.

public SyntaxTriviaList TrailingTrivia { get; }

Property value

SyntaxTriviaList

Gets the decoded value of the token, which may be a number or another type the language chose.

public object? Value { get; }

Property value

object?

Gets the value the text denotes, which is the text itself unless the language decoded something else.

public string ValueText { get; }

Property value

string

Methods

NameDescription
CopyAnnotationsTo(SyntaxToken)Returns token carrying this token's annotations as well as its own.
Equals(SyntaxToken)
Equals(object?)
GetAnnotations()Gets all the annotations of this token.
GetAnnotations(string)Gets the annotations of this token of the given kind.
GetHashCode()
GetNextToken()Returns the token that comes after this one in the tree, or SyntaxToken.None when there is none.
GetPreviousToken()Returns the token that comes before this one in the tree, or SyntaxToken.None when there is none.
HasAnnotation(SyntaxAnnotation?)Determines whether this token carries annotation.
HasAnnotations(string)Determines whether this token carries an annotation of the given kind.
IsEquivalentTo(SyntaxToken)Determines whether the two tokens have the same kind and text, ignoring the trivia around them.
IsIncrementallyIdenticalTo(SyntaxToken)Determines whether the two tokens are backed by the very same immutable token, which happens when one tree was derived from the other and this token was left untouched.
ToFullString()Returns the text of this token, including its trivia.
ToString()Returns the text of this token, excluding its trivia.
WithAdditionalAnnotations(SyntaxAnnotation[])Returns this token carrying annotations as well as the ones it already has.
WithLeadingTrivia(SyntaxTrivia[])Returns this token with trivia in front of its text.
WithLeadingTrivia(IEnumerable<SyntaxTrivia>?)Returns this token with trivia in front of its text.
WithTrailingTrivia(SyntaxTrivia[])Returns this token with trivia after its text.
WithTrailingTrivia(IEnumerable<SyntaxTrivia>?)Returns this token with trivia after its text.
WithTriviaFrom(SyntaxToken)Returns this token carrying the trivia of token on both sides.
WithoutAnnotations(SyntaxAnnotation[])Returns this token without annotations.
WithoutAnnotations(string)Returns this token without any annotation of the given kind.
WriteTo(TextWriter)

CopyAnnotationsTo(SyntaxToken)

SyntaxToken.cs

Returns token carrying this token's annotations as well as its own.

public SyntaxToken CopyAnnotationsTo(SyntaxToken token)

Parameters

token SyntaxToken

Returns

SyntaxToken

Equals overloads

Equals(SyntaxToken)

SyntaxToken.cs
public bool Equals(SyntaxToken other)
Parameters
other SyntaxToken
Returns

bool

No documentation is available.

Equals(object?)

SyntaxToken.cs
public override bool Equals(object? obj)
Parameters
obj object?
Returns

bool

No documentation is available.

GetAnnotations overloads

GetAnnotations()

SyntaxToken.cs

Gets all the annotations of this token.

public IEnumerable<SyntaxAnnotation> GetAnnotations()

GetAnnotations(string)

SyntaxToken.cs

Gets the annotations of this token of the given kind.

public IEnumerable<SyntaxAnnotation> GetAnnotations(string annotationKind)
Parameters
annotationKind string
Returns

IEnumerable<SyntaxAnnotation>

Exceptions
ArgumentNullException
annotationKind is null.

GetHashCode()

SyntaxToken.cs
public override int GetHashCode()

Returns

int

No documentation is available.

GetNextToken()

SyntaxToken.cs

Returns the token that comes after this one in the tree, or SyntaxToken.None when there is none.

public SyntaxToken GetNextToken()

GetPreviousToken()

SyntaxToken.cs

Returns the token that comes before this one in the tree, or SyntaxToken.None when there is none.

public SyntaxToken GetPreviousToken()

HasAnnotation(SyntaxAnnotation?)

SyntaxToken.cs

Determines whether this token carries annotation.

public bool HasAnnotation(SyntaxAnnotation? annotation)

Parameters

annotation SyntaxAnnotation?

Returns

bool

HasAnnotations(string)

SyntaxToken.cs

Determines whether this token carries an annotation of the given kind.

public bool HasAnnotations(string annotationKind)

Parameters

annotationKind string

Returns

bool

IsEquivalentTo(SyntaxToken)

SyntaxToken.cs

Determines whether the two tokens have the same kind and text, ignoring the trivia around them.

public bool IsEquivalentTo(SyntaxToken token)

Parameters

token SyntaxToken

Returns

bool

IsIncrementallyIdenticalTo(SyntaxToken)

SyntaxToken.cs

Determines whether the two tokens are backed by the very same immutable token, which happens when one tree was derived from the other and this token was left untouched.

public bool IsIncrementallyIdenticalTo(SyntaxToken token)

Parameters

token SyntaxToken

Returns

bool

ToFullString()

SyntaxToken.cs

Returns the text of this token, including its trivia.

public string ToFullString()

Returns

string

ToString()

SyntaxToken.cs

Returns the text of this token, excluding its trivia.

public override string ToString()

Returns

string

WithAdditionalAnnotations(SyntaxAnnotation[])

SyntaxToken.cs

Returns this token carrying annotations as well as the ones it already has.

public SyntaxToken WithAdditionalAnnotations(params SyntaxAnnotation[] annotations)

Parameters

annotations SyntaxAnnotation[]

Returns

SyntaxToken

WithLeadingTrivia overloads

WithLeadingTrivia(SyntaxTrivia[])

SyntaxToken.cs

Returns this token with trivia in front of its text.

public SyntaxToken WithLeadingTrivia(params SyntaxTrivia[] trivia)
Parameters
trivia SyntaxTrivia[]
Returns

SyntaxToken

WithLeadingTrivia(IEnumerable<SyntaxTrivia>?)

SyntaxToken.cs

Returns this token with trivia in front of its text.

public SyntaxToken WithLeadingTrivia(IEnumerable<SyntaxTrivia>? trivia)

WithTrailingTrivia overloads

WithTrailingTrivia(SyntaxTrivia[])

SyntaxToken.cs

Returns this token with trivia after its text.

public SyntaxToken WithTrailingTrivia(params SyntaxTrivia[] trivia)
Parameters
trivia SyntaxTrivia[]
Returns

SyntaxToken

WithTrailingTrivia(IEnumerable<SyntaxTrivia>?)

SyntaxToken.cs

Returns this token with trivia after its text.

public SyntaxToken WithTrailingTrivia(IEnumerable<SyntaxTrivia>? trivia)

WithTriviaFrom(SyntaxToken)

SyntaxToken.cs

Returns this token carrying the trivia of token on both sides.

public SyntaxToken WithTriviaFrom(SyntaxToken token)

Parameters

token SyntaxToken

Returns

SyntaxToken

WithoutAnnotations overloads

WithoutAnnotations(SyntaxAnnotation[])

SyntaxToken.cs

Returns this token without annotations.

public SyntaxToken WithoutAnnotations(params SyntaxAnnotation[] annotations)
Parameters
annotations SyntaxAnnotation[]
Returns

SyntaxToken

WithoutAnnotations(string)

SyntaxToken.cs

Returns this token without any annotation of the given kind.

public SyntaxToken WithoutAnnotations(string annotationKind)
Parameters
annotationKind string
Returns

SyntaxToken

WriteTo(TextWriter)

SyntaxToken.cs
public void WriteTo(TextWriter writer)

Parameters

writer TextWriter

Exceptions

ArgumentNullException
writer is null.

Operators

NameDescription
operator ==(SyntaxToken, SyntaxToken)
operator !=(SyntaxToken, SyntaxToken)

operator ==(SyntaxToken, SyntaxToken)

SyntaxToken.cs
public static bool operator ==(SyntaxToken left, SyntaxToken right)

Parameters

left SyntaxToken
right SyntaxToken

Returns

bool

No documentation is available.

operator !=(SyntaxToken, SyntaxToken)

SyntaxToken.cs
public static bool operator !=(SyntaxToken left, SyntaxToken right)

Parameters

left SyntaxToken
right SyntaxToken

Returns

bool

No documentation is available.