SeparatedSyntaxList<TNode> Struct

A sequence of nodes with a separator token between each pair, and optionally one after the last.

public readonly struct SeparatedSyntaxList<TNode> : IEnumerable<TNode>, IReadOnlyCollection<TNode>, IReadOnlyList<TNode>, IEnumerable, IEquatable<SeparatedSyntaxList<TNode>> where TNode : SyntaxNode

Type parameters

TNode
The type of the nodes in the list.

Remarks

Elements and separators share one underlying sequence, alternating: even positions hold nodes, odd positions hold separators. A list that ends on a separator therefore has as many separators as elements, which is how a trailing comma is represented without any extra machinery.

The alternation is the parser's responsibility. A parser that has nothing to put between two separators must insert a missing node, or reading the list will fail on a separator where an element was expected.

Implements

Nested types

NameDescription
SeparatedSyntaxList<TNode>.EnumeratorWalks a SeparatedSyntaxList<TNode> without allocating.

Constructors

NameDescription
SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken>)Creates a detached list from nodesAndSeparators, which must alternate.

SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken>)

SeparatedSyntaxList.cs

Creates a detached list from nodesAndSeparators, which must alternate.

public SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken> nodesAndSeparators)

Parameters

nodesAndSeparators IEnumerable<SyntaxNodeOrToken>

Exceptions

ArgumentNullException
nodesAndSeparators is null.

Properties

NameDescription
CountGets the number of nodes, not counting separators.
FullSpan
HasTrailingSeparatorGets a value indicating whether a separator follows the last node, as in [1, 2, ].
SeparatorCountGets the number of separators, which equals SeparatedSyntaxList<TNode>.Count when the list ends on one.
Span

Gets the number of nodes, not counting separators.

public int Count { get; }

Property value

int

public TextSpan FullSpan { get; }

Property value

TextSpan

No documentation is available.

HasTrailingSeparator

SeparatedSyntaxList.cs

Gets a value indicating whether a separator follows the last node, as in [1, 2, ].

public bool HasTrailingSeparator { get; }

Property value

bool

Gets the number of separators, which equals SeparatedSyntaxList<TNode>.Count when the list ends on one.

public int SeparatorCount { get; }

Property value

int

public TextSpan Span { get; }

Property value

TextSpan

No documentation is available.

Indexers

NameDescription
this[int]
public TNode this[int index] { get; }

Parameters

index int

Property value

TNode

No documentation is available.

Methods

NameDescription
Add(TNode)Returns a detached list with node appended, adding a separator when one is needed.
AddRange(IEnumerable<TNode>)Returns a detached list with nodes appended.
Any()
Equals(SeparatedSyntaxList<TNode>)
Equals(object?)
First()
FirstOrDefault()
GetEnumerator()
GetHashCode()
GetSeparator(int)Gets the separator that follows the node at index.
GetSeparators()Gets the separators of this list.
GetWithSeparators()Gets the nodes and the separators together, in source order.
IndexOf(Func<TNode, bool>)Finds the first node matching predicate, or -1.
IndexOf(TNode)
Insert(int, TNode)Returns a detached list with node at index, adding the separator the alternation needs.
Last()
LastOrDefault()
Remove(TNode)Returns a detached list without node, or this list when it does not contain it.
RemoveAt(int)Returns a detached list without the node at index and its separator.
Replace(TNode, TNode)Returns a detached list with newNode in place of nodeInList.
ReplaceSeparator(SyntaxToken, SyntaxToken)Returns a detached list with newSeparator in place of separatorToken.
System.Collections.Generic.IEnumerable<TNode>.GetEnumerator()
System.Collections.IEnumerable.GetEnumerator()
ToFullString()
ToString()

Returns a detached list with node appended, adding a separator when one is needed.

public SeparatedSyntaxList<TNode> Add(TNode node)

Parameters

node TNode

Returns

SeparatedSyntaxList<TNode>

AddRange(IEnumerable<TNode>)

SeparatedSyntaxList.cs

Returns a detached list with nodes appended.

public SeparatedSyntaxList<TNode> AddRange(IEnumerable<TNode> nodes)

Parameters

nodes IEnumerable<TNode>

Returns

SeparatedSyntaxList<TNode>

Exceptions

ArgumentNullException
nodes is null.
public bool Any()

Returns

bool

No documentation is available.

Equals overloads

Equals(SeparatedSyntaxList<TNode>)

SeparatedSyntaxList.cs
public bool Equals(SeparatedSyntaxList<TNode> other)
Parameters
other SeparatedSyntaxList<TNode>
Returns

bool

No documentation is available.

Equals(object?)

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

bool

No documentation is available.

public TNode? First()

Returns

TNode?

No documentation is available.

FirstOrDefault()

SeparatedSyntaxList.cs
public TNode? FirstOrDefault()

Returns

TNode?

No documentation is available.

GetEnumerator()

SeparatedSyntaxList.cs
public SeparatedSyntaxList<TNode>.Enumerator GetEnumerator()

No documentation is available.

public override int GetHashCode()

Returns

int

No documentation is available.

GetSeparator(int)

SeparatedSyntaxList.cs

Gets the separator that follows the node at index.

public SyntaxToken GetSeparator(int index)

Parameters

index int

Returns

SyntaxToken

GetSeparators()

SeparatedSyntaxList.cs

Gets the separators of this list.

public IEnumerable<SyntaxToken> GetSeparators()

GetWithSeparators()

SeparatedSyntaxList.cs

Gets the nodes and the separators together, in source order.

public SyntaxNodeOrTokenList GetWithSeparators()

IndexOf overloads

IndexOf(Func<TNode, bool>)

SeparatedSyntaxList.cs

Finds the first node matching predicate, or -1.

public int IndexOf(Func<TNode, bool> predicate)
Parameters
predicate Func<TNode, bool>
Returns

int

Exceptions
ArgumentNullException
predicate is null.
public int IndexOf(TNode node)
Parameters
node TNode
Returns

int

No documentation is available.

Insert(int, TNode)

SeparatedSyntaxList.cs

Returns a detached list with node at index, adding the separator the alternation needs.

public SeparatedSyntaxList<TNode> Insert(int index, TNode node)

Parameters

index int
node TNode

Returns

SeparatedSyntaxList<TNode>

Exceptions

ArgumentNullException
node is null.
InvalidOperationException
The language does not define a separator for its lists.
public TNode? Last()

Returns

TNode?

No documentation is available.

LastOrDefault()

SeparatedSyntaxList.cs
public TNode? LastOrDefault()

Returns

TNode?

No documentation is available.

Returns a detached list without node, or this list when it does not contain it.

public SeparatedSyntaxList<TNode> Remove(TNode node)

Parameters

node TNode

Returns

SeparatedSyntaxList<TNode>

Returns a detached list without the node at index and its separator.

public SeparatedSyntaxList<TNode> RemoveAt(int index)

Parameters

index int

Returns

SeparatedSyntaxList<TNode>

Replace(TNode, TNode)

SeparatedSyntaxList.cs

Returns a detached list with newNode in place of nodeInList.

public SeparatedSyntaxList<TNode> Replace(TNode nodeInList, TNode newNode)

Parameters

nodeInList TNode
newNode TNode

Returns

SeparatedSyntaxList<TNode>

Exceptions

ArgumentNullException
newNode is null.
ArgumentException
nodeInList is not in this list.

ReplaceSeparator(SyntaxToken, SyntaxToken)

SeparatedSyntaxList.cs

Returns a detached list with newSeparator in place of separatorToken.

public SeparatedSyntaxList<TNode> ReplaceSeparator(SyntaxToken separatorToken, SyntaxToken newSeparator)

Parameters

separatorToken SyntaxToken
newSeparator SyntaxToken

Returns

SeparatedSyntaxList<TNode>

Exceptions

ArgumentException
separatorToken is not a separator of this list.

System.Collections.Generic.IEnumerable<TNode>.GetEnumerator()

SeparatedSyntaxList.cs
IEnumerator<TNode> IEnumerable<TNode>.GetEnumerator()

No documentation is available.

System.Collections.IEnumerable.GetEnumerator()

SeparatedSyntaxList.cs
IEnumerator IEnumerable.GetEnumerator()

No documentation is available.

public string ToFullString()

Returns

string

No documentation is available.

public override string ToString()

Returns

string

No documentation is available.

Operators

NameDescription
operator ==(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)
implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode>)
operator !=(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)

operator ==(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)

SeparatedSyntaxList.cs
public static bool operator ==(SeparatedSyntaxList<TNode> left, SeparatedSyntaxList<TNode> right)

No documentation is available.

implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode>)

SeparatedSyntaxList.cs
public static implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode> nodes)

No documentation is available.

operator !=(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)

SeparatedSyntaxList.cs
public static bool operator !=(SeparatedSyntaxList<TNode> left, SeparatedSyntaxList<TNode> right)

No documentation is available.