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 : SyntaxNodeType 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
| Name | Description |
|---|---|
| SeparatedSyntaxList<TNode>.Enumerator | Walks a SeparatedSyntaxList<TNode> without allocating. |
Constructors
| Name | Description |
|---|---|
| SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken>) | Creates a detached list from nodesAndSeparators, which must alternate. |
SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken>)
SeparatedSyntaxList.csCreates a detached list from nodesAndSeparators, which must alternate.
public SeparatedSyntaxList(IEnumerable<SyntaxNodeOrToken> nodesAndSeparators)Parameters
nodesAndSeparatorsIEnumerable<SyntaxNodeOrToken>
Exceptions
ArgumentNullExceptionnodesAndSeparatorsisnull.
Properties
| Name | Description |
|---|---|
| Count | Gets the number of nodes, not counting separators. |
| FullSpan | |
| HasTrailingSeparator | Gets a value indicating whether a separator follows the last node, as in [1, 2, ]. |
| SeparatorCount | Gets the number of separators, which equals SeparatedSyntaxList<TNode>.Count when the list ends on one. |
| Span |
FullSpan
SeparatedSyntaxList.csHasTrailingSeparator
SeparatedSyntaxList.csSeparatorCount
SeparatedSyntaxList.csGets the number of separators, which equals SeparatedSyntaxList<TNode>.Count when the list ends on one.
public int SeparatorCount { get; }Property value
Indexers
| Name | Description |
|---|---|
| this[int] |
this[int]
SeparatedSyntaxList.csMethods
| Name | Description |
|---|---|
| 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() |
Add(TNode)
SeparatedSyntaxList.csReturns a detached list with node appended, adding a separator when one is needed.
public SeparatedSyntaxList<TNode> Add(TNode node)AddRange(IEnumerable<TNode>)
SeparatedSyntaxList.csReturns a detached list with nodes appended.
public SeparatedSyntaxList<TNode> AddRange(IEnumerable<TNode> nodes)Equals overloads
Equals(SeparatedSyntaxList<TNode>)
SeparatedSyntaxList.cspublic bool Equals(SeparatedSyntaxList<TNode> other)No documentation is available.
Equals(object?)
SeparatedSyntaxList.csFirst()
SeparatedSyntaxList.cspublic TNode? First()Returns
TNode?
No documentation is available.
FirstOrDefault()
SeparatedSyntaxList.cspublic TNode? FirstOrDefault()Returns
TNode?
No documentation is available.
GetEnumerator()
SeparatedSyntaxList.cspublic SeparatedSyntaxList<TNode>.Enumerator GetEnumerator()No documentation is available.
GetHashCode()
SeparatedSyntaxList.csGetSeparator(int)
SeparatedSyntaxList.csGets the separator that follows the node at index.
public SyntaxToken GetSeparator(int index)GetSeparators()
SeparatedSyntaxList.csGetWithSeparators()
SeparatedSyntaxList.csGets the nodes and the separators together, in source order.
public SyntaxNodeOrTokenList GetWithSeparators()Returns
IndexOf overloads
IndexOf(Func<TNode, bool>)
SeparatedSyntaxList.csFinds the first node matching predicate, or -1.
IndexOf(TNode)
SeparatedSyntaxList.csInsert(int, TNode)
SeparatedSyntaxList.csReturns a detached list with node at index, adding the separator the alternation needs.
public SeparatedSyntaxList<TNode> Insert(int index, TNode node)Parameters
indexintnodeTNode
Returns
Exceptions
ArgumentNullExceptionnodeisnull.InvalidOperationException- The language does not define a separator for its lists.
Last()
SeparatedSyntaxList.cspublic TNode? Last()Returns
TNode?
No documentation is available.
LastOrDefault()
SeparatedSyntaxList.cspublic TNode? LastOrDefault()Returns
TNode?
No documentation is available.
Remove(TNode)
SeparatedSyntaxList.csReturns a detached list without node, or this list when it does not contain it.
public SeparatedSyntaxList<TNode> Remove(TNode node)RemoveAt(int)
SeparatedSyntaxList.csReturns a detached list without the node at index and its separator.
public SeparatedSyntaxList<TNode> RemoveAt(int index)Replace(TNode, TNode)
SeparatedSyntaxList.csReturns a detached list with newNode in place of nodeInList.
public SeparatedSyntaxList<TNode> Replace(TNode nodeInList, TNode newNode)Parameters
nodeInListTNodenewNodeTNode
Returns
Exceptions
ArgumentNullExceptionnewNodeisnull.ArgumentExceptionnodeInListis not in this list.
ReplaceSeparator(SyntaxToken, SyntaxToken)
SeparatedSyntaxList.csReturns a detached list with newSeparator in place of separatorToken.
public SeparatedSyntaxList<TNode> ReplaceSeparator(SyntaxToken separatorToken, SyntaxToken newSeparator)Parameters
separatorTokenSyntaxTokennewSeparatorSyntaxToken
Returns
Exceptions
ArgumentExceptionseparatorTokenis not a separator of this list.
System.Collections.Generic.IEnumerable<TNode>.GetEnumerator()
SeparatedSyntaxList.csSystem.Collections.IEnumerable.GetEnumerator()
SeparatedSyntaxList.csToFullString()
SeparatedSyntaxList.csToString()
SeparatedSyntaxList.csOperators
operator ==(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)
SeparatedSyntaxList.cspublic static bool operator ==(SeparatedSyntaxList<TNode> left, SeparatedSyntaxList<TNode> right)No documentation is available.
implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode>)
SeparatedSyntaxList.cspublic static implicit operator SeparatedSyntaxList<SyntaxNode>(SeparatedSyntaxList<TNode> nodes)No documentation is available.
operator !=(SeparatedSyntaxList<TNode>, SeparatedSyntaxList<TNode>)
SeparatedSyntaxList.cspublic static bool operator !=(SeparatedSyntaxList<TNode> left, SeparatedSyntaxList<TNode> right)No documentation is available.