SyntaxFactory Class

Builds INI nodes, tokens, and trivia.

public static class SyntaxFactory

Remarks

A node built here is not part of any document, so its span starts at zero. Putting it into a tree with SyntaxNodeExtensions.ReplaceNode gives it a real position, without re-reading any text.

The methods that take a key, a section name, or a value check that the text reads back as that same key, name, or value, so an edit cannot change the rest of the document. Without IniParseOptions, they check it whatever IniParseOptions.InlineComments is, and SyntaxFactory.Value quotes a value that would not read back otherwise. With options, they check it the way a document read with those options reads it, and quote only what those options require.

Properties

NameDescription
CarriageReturnLineFeedA Windows line break.
LineFeedA Unix line break.
SpaceA single space.
TabA single tab.

CarriageReturnLineFeed

SyntaxFactory.cs

A Windows line break.

public static SyntaxTrivia CarriageReturnLineFeed { get; }

Property value

SyntaxTrivia

A Unix line break.

public static SyntaxTrivia LineFeed { get; }

Property value

SyntaxTrivia

A single space.

public static SyntaxTrivia Space { get; }

Property value

SyntaxTrivia

A single tab.

public static SyntaxTrivia Tab { get; }

Property value

SyntaxTrivia

Methods

NameDescription
AreEquivalent(IniSyntaxNode?, IniSyntaxNode?)Determines whether the two nodes have the same structure and text.
BadToken(string)Creates a token holding text the parser could make no sense of.
Comment(string)Creates comment trivia.
EndOfLine(string)
IniDocument(IniEntrySyntax[])Creates a document from entries, ending the line of each that does not end its own.
IniDocument(SyntaxList<IniEntrySyntax>, SyntaxToken)Creates a document from entries, ending the line of each one that another follows.
IniProperty(SyntaxToken, SyntaxToken, SyntaxToken)
IniProperty(SyntaxToken, SyntaxToken, SyntaxToken, SyntaxTokenList)Creates a property whose value continues on the lines of continuationTokens.
IniProperty(string, string)Creates key=value, quoting value when it has to be, and ending with a line feed like every line of a document.
IniProperty(string, string, IniParseOptions)Creates key=value for a document read with options, quoting value only when they require it, and ending with a line feed like every line of a document.
IniSection(SyntaxToken, SyntaxToken, SyntaxToken)
IniSection(string)Creates a section header such as [database], ending with a line feed like every line of a document.
IniSection(string, IniParseOptions)Creates a section header such as [database] for a document read with options, ending with a line feed like every line of a document.
IniSkippedText(SyntaxTokenList)
IniSkippedText(string)
Key(string)Creates a key token written exactly as text.
Key(string, IniParseOptions)Creates a key token written exactly as text, for a document read with options.
List<TNode>()
List<TNode>(IEnumerable<TNode>)
MissingToken(SyntaxKind)Creates a zero-width token standing in for one the text does not have.
ParseDocument(string)Parses text and returns its root.
ParseDocument(string, IniParseOptions?)Parses text and returns its root.
ParseSyntaxTree(string, IniParseOptions?, string?)Parses text into a tree.
ParseSyntaxTree(string, string?)Parses text into a tree.
RawValue(string)Creates a value token written exactly as text, quotes included.
SectionName(string)Creates a section name token written exactly as text.
SectionName(string, IniParseOptions)Creates a section name token written exactly as text, for a document read with options.
SingletonList<TNode>(TNode)
Token(SyntaxKind)Creates a token whose text is fixed by its kind, such as a bracket or separator.
Token(SyntaxTriviaList, SyntaxKind, SyntaxTriviaList)Creates a token with trivia on either side.
TokenList()
TokenList(SyntaxToken)
TokenList(SyntaxToken[])
TokenList(IEnumerable<SyntaxToken>)
Trivia(SyntaxKind, string)Creates trivia of the given kind.
TriviaList()
TriviaList(SyntaxTrivia)
TriviaList(SyntaxTrivia[])
TriviaList(IEnumerable<SyntaxTrivia>)
Value(string)Creates a value token that reads back as value, in quotes when it has to be.
Value(string, IniParseOptions)Creates a value token that reads back as value in a document read with options.
Whitespace(string)

AreEquivalent(IniSyntaxNode?, IniSyntaxNode?)

SyntaxFactory.cs

Determines whether the two nodes have the same structure and text.

public static bool AreEquivalent(IniSyntaxNode? oldNode, IniSyntaxNode? newNode)

Parameters

oldNode IniSyntaxNode?
newNode IniSyntaxNode?

Returns

bool

BadToken(string)

SyntaxFactory.cs

Creates a token holding text the parser could make no sense of.

public static SyntaxToken BadToken(string text)

Parameters

text string

Returns

SyntaxToken

Exceptions

ArgumentNullException
text is null.

Comment(string)

SyntaxFactory.cs

Creates comment trivia.

public static SyntaxTrivia Comment(string text)

Parameters

text string

Returns

SyntaxTrivia

Exceptions

ArgumentNullException
text is null.
ArgumentException
text is not an INI comment.

EndOfLine(string)

SyntaxFactory.cs
public static SyntaxTrivia EndOfLine(string text)

Parameters

text string

Returns

SyntaxTrivia

Exceptions

ArgumentNullException
text is null.
ArgumentException
text is not \n, \r\n, or \r.

IniDocument overloads

IniDocument(IniEntrySyntax[])

SyntaxFactory.cs

Creates a document from entries, ending the line of each that does not end its own.

public static IniDocumentSyntax IniDocument(params IniEntrySyntax[] entries)
Parameters
entries IniEntrySyntax[]
Returns

IniDocumentSyntax

Exceptions
ArgumentNullException
entries is null.

IniDocument(SyntaxList<IniEntrySyntax>, SyntaxToken)

SyntaxFactory.cs

Creates a document from entries, ending the line of each one that another follows.

public static IniDocumentSyntax IniDocument(SyntaxList<IniEntrySyntax> entries, SyntaxToken endOfFileToken)
Parameters
entries SyntaxList<IniEntrySyntax>
endOfFileToken SyntaxToken
Returns

IniDocumentSyntax

Remarks

An entry followed by IniSkippedTextSyntax is left as it is, since that text is the rest of its line.

IniProperty overloads

IniProperty(SyntaxToken, SyntaxToken, SyntaxToken)

SyntaxFactory.cs
public static IniPropertySyntax IniProperty(SyntaxToken keyToken, SyntaxToken separatorToken, SyntaxToken valueToken)
Parameters
keyToken SyntaxToken
separatorToken SyntaxToken
valueToken SyntaxToken
Returns

IniPropertySyntax

Exceptions
ArgumentException
separatorToken is neither = nor :.

IniProperty(SyntaxToken, SyntaxToken, SyntaxToken, SyntaxTokenList)

SyntaxFactory.cs

Creates a property whose value continues on the lines of continuationTokens.

public static IniPropertySyntax IniProperty(SyntaxToken keyToken, SyntaxToken separatorToken, SyntaxToken valueToken, SyntaxTokenList continuationTokens)
Parameters
keyToken SyntaxToken
separatorToken SyntaxToken
valueToken SyntaxToken
continuationTokens SyntaxTokenList
Returns

IniPropertySyntax

Exceptions
ArgumentException
separatorToken is neither = nor :, or one of continuationTokens is not a SyntaxKind.ValueToken.
Remarks

Each continuation token is a SyntaxKind.ValueToken for one line, whose leading trivia holds the blank lines and comment lines in front of it and its indentation. Only a document read with IniParseOptions.AllowMultilineValues reads them back as part of the value.

IniProperty(string, string)

SyntaxFactory.cs

Creates key=value, quoting value when it has to be, and ending with a line feed like every line of a document.

public static IniPropertySyntax IniProperty(string key, string value)
Parameters
key string
value string
Returns

IniPropertySyntax

Exceptions
ArgumentNullException
key or value is null.
ArgumentException
key cannot be written as a key, or value as a value; see SyntaxFactory.Key and SyntaxFactory.Value.

IniProperty(string, string, IniParseOptions)

SyntaxFactory.cs

Creates key=value for a document read with options, quoting value only when they require it, and ending with a line feed like every line of a document.

public static IniPropertySyntax IniProperty(string key, string value, IniParseOptions options)
Parameters
key string
value string
options IniParseOptions
Returns

IniPropertySyntax

Exceptions
ArgumentNullException
An argument is null.
ArgumentException
key cannot be written as a key, or value as a value under options; see SyntaxFactory.Key and SyntaxFactory.Value. A value with line breaks cannot end with an empty line.
Remarks

When IniParseOptions.AllowMultilineValues is true, a value with line breaks continues on the lines below the key, indented by four spaces. Its lines are joined with \n when it is read back, whichever of \r\n, \r, or \n separated them.

IniSection overloads

IniSection(SyntaxToken, SyntaxToken, SyntaxToken)

SyntaxFactory.cs
public static IniSectionSyntax IniSection(SyntaxToken openBracketToken, SyntaxToken nameToken, SyntaxToken closeBracketToken)
Parameters
openBracketToken SyntaxToken
nameToken SyntaxToken
closeBracketToken SyntaxToken
Returns

IniSectionSyntax

No documentation is available.

IniSection(string)

SyntaxFactory.cs

Creates a section header such as [database], ending with a line feed like every line of a document.

public static IniSectionSyntax IniSection(string name)
Parameters
name string
Returns

IniSectionSyntax

Exceptions
ArgumentNullException
name is null.
ArgumentException
name cannot be written as a section name; see SyntaxFactory.SectionName.

IniSection(string, IniParseOptions)

SyntaxFactory.cs

Creates a section header such as [database] for a document read with options, ending with a line feed like every line of a document.

public static IniSectionSyntax IniSection(string name, IniParseOptions options)
Parameters
name string
options IniParseOptions
Returns

IniSectionSyntax

Exceptions
ArgumentNullException
name or options is null.
ArgumentException
name cannot be written as a section name; see SyntaxFactory.SectionName.

IniSkippedText overloads

IniSkippedText(SyntaxTokenList)

SyntaxFactory.cs
public static IniSkippedTextSyntax IniSkippedText(SyntaxTokenList tokens)
Parameters
tokens SyntaxTokenList
Returns

IniSkippedTextSyntax

No documentation is available.

IniSkippedText(string)

SyntaxFactory.cs
public static IniSkippedTextSyntax IniSkippedText(string text)
Parameters
text string
Returns

IniSkippedTextSyntax

Exceptions
ArgumentNullException
text is null.

Key overloads

Key(string)

SyntaxFactory.cs

Creates a key token written exactly as text.

public static SyntaxToken Key(string text)
Parameters
text string
Returns

SyntaxToken

Exceptions
ArgumentNullException
text is null.
ArgumentException
text would not read back as this key: it is empty, starts with [, ;, or #, has whitespace around it, or holds =, :, ;, #, or a line break.

Key(string, IniParseOptions)

SyntaxFactory.cs

Creates a key token written exactly as text, for a document read with options.

public static SyntaxToken Key(string text, IniParseOptions options)
Parameters
text string
options IniParseOptions
Returns

SyntaxToken

Exceptions
ArgumentNullException
text or options is null.
ArgumentException
text would not read back as this key under options: it is empty, starts with [, ;, or #, has whitespace around it, holds =, :, or a line break, or holds a ; or # that would start a comment.
Remarks

A key may hold ; and # where options do not read them as the start of a comment, such as C# when IniParseOptions.InlineComments is IniInlineCommentMode.AfterWhitespace.

List overloads

List<TNode>()

SyntaxFactory.cs
public static SyntaxList<TNode> List<TNode>() where TNode : IniSyntaxNode
Type parameters
TNode
Returns

SyntaxList<TNode>

No documentation is available.

List<TNode>(IEnumerable<TNode>)

SyntaxFactory.cs
public static SyntaxList<TNode> List<TNode>(IEnumerable<TNode> nodes) where TNode : IniSyntaxNode
Type parameters
TNode
Parameters
nodes IEnumerable<TNode>
Returns

SyntaxList<TNode>

Exceptions
ArgumentNullException
nodes is null.

MissingToken(SyntaxKind)

SyntaxFactory.cs

Creates a zero-width token standing in for one the text does not have.

public static SyntaxToken MissingToken(SyntaxKind kind)

Parameters

kind SyntaxKind

Returns

SyntaxToken

ParseDocument overloads

ParseDocument(string)

SyntaxFactory.cs

Parses text and returns its root.

public static IniDocumentSyntax ParseDocument(string text)
Parameters
text string
Returns

IniDocumentSyntax

Exceptions
ArgumentNullException
text is null.

ParseDocument(string, IniParseOptions?)

SyntaxFactory.cs

Parses text and returns its root.

public static IniDocumentSyntax ParseDocument(string text, IniParseOptions? options)
Parameters
text string
options IniParseOptions?
Returns

IniDocumentSyntax

Exceptions
ArgumentNullException
text is null.

ParseSyntaxTree overloads

ParseSyntaxTree(string, IniParseOptions?, string?)

SyntaxFactory.cs

Parses text into a tree.

public static IniSyntaxTree ParseSyntaxTree(string text, IniParseOptions? options, string? path = null)
Parameters
text string
options IniParseOptions?
path string?
Returns

IniSyntaxTree

Exceptions
ArgumentNullException
text is null.

ParseSyntaxTree(string, string?)

SyntaxFactory.cs

Parses text into a tree.

public static IniSyntaxTree ParseSyntaxTree(string text, string? path = null)
Parameters
text string
path string?
Returns

IniSyntaxTree

Exceptions
ArgumentNullException
text is null.

RawValue(string)

SyntaxFactory.cs

Creates a value token written exactly as text, quotes included.

public static SyntaxToken RawValue(string text)

Parameters

text string

Returns

SyntaxToken

Exceptions

ArgumentNullException
text is null.
ArgumentException
text would not read back as one value: it has whitespace around it, a line break, or a ; or # outside quotes.

SectionName overloads

SectionName(string)

SyntaxFactory.cs

Creates a section name token written exactly as text.

public static SyntaxToken SectionName(string text)
Parameters
text string
Returns

SyntaxToken

Exceptions
ArgumentNullException
text is null.
ArgumentException
text would not read back as this name: it is empty, has whitespace around it, or holds ], ;, #, or a line break.

SectionName(string, IniParseOptions)

SyntaxFactory.cs

Creates a section name token written exactly as text, for a document read with options.

public static SyntaxToken SectionName(string text, IniParseOptions options)
Parameters
text string
options IniParseOptions
Returns

SyntaxToken

Exceptions
ArgumentNullException
text or options is null.
ArgumentException
text would not read back as this name under options: it is empty, has whitespace around it, holds ] or a line break, or holds a ; or # that would start a comment.

SingletonList<TNode>(TNode)

SyntaxFactory.cs
public static SyntaxList<TNode> SingletonList<TNode>(TNode node) where TNode : IniSyntaxNode

Type parameters

TNode

Parameters

node TNode

Returns

SyntaxList<TNode>

No documentation is available.

Token overloads

Token(SyntaxKind)

SyntaxFactory.cs

Creates a token whose text is fixed by its kind, such as a bracket or separator.

public static SyntaxToken Token(SyntaxKind kind)
Parameters
kind SyntaxKind
Returns

SyntaxToken

Token(SyntaxTriviaList, SyntaxKind, SyntaxTriviaList)

SyntaxFactory.cs

Creates a token with trivia on either side.

public static SyntaxToken Token(SyntaxTriviaList leading, SyntaxKind kind, SyntaxTriviaList trailing)
Parameters
leading SyntaxTriviaList
kind SyntaxKind
trailing SyntaxTriviaList
Returns

SyntaxToken

TokenList overloads

TokenList()

SyntaxFactory.cs
public static SyntaxTokenList TokenList()

No documentation is available.

TokenList(SyntaxToken)

SyntaxFactory.cs
public static SyntaxTokenList TokenList(SyntaxToken token)
Parameters
token SyntaxToken
Returns

SyntaxTokenList

No documentation is available.

TokenList(SyntaxToken[])

SyntaxFactory.cs
public static SyntaxTokenList TokenList(params SyntaxToken[] tokens)
Parameters
tokens SyntaxToken[]
Returns

SyntaxTokenList

No documentation is available.

TokenList(IEnumerable<SyntaxToken>)

SyntaxFactory.cs
public static SyntaxTokenList TokenList(IEnumerable<SyntaxToken> tokens)
Parameters
tokens IEnumerable<SyntaxToken>
Returns

SyntaxTokenList

Exceptions
ArgumentNullException
tokens is null.

Trivia(SyntaxKind, string)

SyntaxFactory.cs

Creates trivia of the given kind.

public static SyntaxTrivia Trivia(SyntaxKind kind, string text)

Parameters

kind SyntaxKind
text string

Returns

SyntaxTrivia

Exceptions

ArgumentNullException
text is null.
ArgumentException
text is not trivia of that kind, or kind is not a kind of trivia.

TriviaList overloads

TriviaList()

SyntaxFactory.cs
public static SyntaxTriviaList TriviaList()

No documentation is available.

TriviaList(SyntaxTrivia)

SyntaxFactory.cs
public static SyntaxTriviaList TriviaList(SyntaxTrivia trivia)
Parameters
trivia SyntaxTrivia
Returns

SyntaxTriviaList

No documentation is available.

TriviaList(SyntaxTrivia[])

SyntaxFactory.cs
public static SyntaxTriviaList TriviaList(params SyntaxTrivia[] trivia)
Parameters
trivia SyntaxTrivia[]
Returns

SyntaxTriviaList

No documentation is available.

TriviaList(IEnumerable<SyntaxTrivia>)

SyntaxFactory.cs
public static SyntaxTriviaList TriviaList(IEnumerable<SyntaxTrivia> trivia)
Parameters
trivia IEnumerable<SyntaxTrivia>
Returns

SyntaxTriviaList

Exceptions
ArgumentNullException
trivia is null.

Value overloads

Value(string)

SyntaxFactory.cs

Creates a value token that reads back as value, in quotes when it has to be.

public static SyntaxToken Value(string value)
Parameters
value string
Returns

SyntaxToken

Exceptions
ArgumentNullException
value is null.
ArgumentException
value holds a line break, or needs quotes and holds both kinds of quote.
Remarks

A value is quoted when it would otherwise lose part of itself: whitespace around it, a ; or # that could start a comment, or a quote it starts with, which a quote in the comment after it could otherwise close. It is put in double quotes, or in single quotes when it holds a double quote.

Value(string, IniParseOptions)

SyntaxFactory.cs

Creates a value token that reads back as value in a document read with options.

public static SyntaxToken Value(string value, IniParseOptions options)
Parameters
value string
options IniParseOptions
Returns

SyntaxToken

Exceptions
ArgumentNullException
value or options is null.
ArgumentException
value holds a line break, or cannot be written so that options read it back: it needs quotes and they are not allowed, or it holds both kinds of quote.
Remarks

The value is quoted only when it would otherwise lose part of itself under options, and never when IniParseOptions.AllowQuotedValues is false, since quotes are then part of the value.

Whitespace(string)

SyntaxFactory.cs
public static SyntaxTrivia Whitespace(string text)

Parameters

text string

Returns

SyntaxTrivia

Exceptions

ArgumentNullException
text is null.
ArgumentException
text is empty or holds something other than whitespace.

Remarks

A byte order mark, which only the start of a document can hold, is whitespace of its own.