SyntaxFactory Class
Builds INI nodes, tokens, and trivia.
public static class SyntaxFactoryRemarks
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
| Name | Description |
|---|---|
| CarriageReturnLineFeed | A Windows line break. |
| LineFeed | A Unix line break. |
| Space | A single space. |
| Tab | A single tab. |
CarriageReturnLineFeed
SyntaxFactory.csLineFeed
SyntaxFactory.csSpace
SyntaxFactory.csMethods
| Name | Description |
|---|---|
| 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.csDetermines whether the two nodes have the same structure and text.
public static bool AreEquivalent(IniSyntaxNode? oldNode, IniSyntaxNode? newNode)BadToken(string)
SyntaxFactory.csCreates a token holding text the parser could make no sense of.
public static SyntaxToken BadToken(string text)Comment(string)
SyntaxFactory.csCreates comment trivia.
public static SyntaxTrivia Comment(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis not an INI comment.
EndOfLine(string)
SyntaxFactory.cspublic static SyntaxTrivia EndOfLine(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis not\n,\r\n, or\r.
IniDocument overloads
IniDocument(IniEntrySyntax[])
SyntaxFactory.csCreates a document from entries, ending the line of each that does not end its own.
public static IniDocumentSyntax IniDocument(params IniEntrySyntax[] entries)IniDocument(SyntaxList<IniEntrySyntax>, SyntaxToken)
SyntaxFactory.csCreates a document from entries, ending the line of each one that another follows.
public static IniDocumentSyntax IniDocument(SyntaxList<IniEntrySyntax> entries, SyntaxToken endOfFileToken)Parameters
entriesSyntaxList<IniEntrySyntax>endOfFileTokenSyntaxToken
Returns
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.cspublic static IniPropertySyntax IniProperty(SyntaxToken keyToken, SyntaxToken separatorToken, SyntaxToken valueToken)Parameters
keyTokenSyntaxTokenseparatorTokenSyntaxTokenvalueTokenSyntaxToken
Returns
Exceptions
ArgumentExceptionseparatorTokenis neither=nor:.
IniProperty(SyntaxToken, SyntaxToken, SyntaxToken, SyntaxTokenList)
SyntaxFactory.csCreates a property whose value continues on the lines of continuationTokens.
public static IniPropertySyntax IniProperty(SyntaxToken keyToken, SyntaxToken separatorToken, SyntaxToken valueToken, SyntaxTokenList continuationTokens)Parameters
keyTokenSyntaxTokenseparatorTokenSyntaxTokenvalueTokenSyntaxTokencontinuationTokensSyntaxTokenList
Returns
Exceptions
ArgumentExceptionseparatorTokenis neither=nor:, or one ofcontinuationTokensis not aSyntaxKind.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.csCreates 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
Returns
Exceptions
ArgumentNullExceptionkeyorvalueisnull.ArgumentExceptionkeycannot be written as a key, orvalueas a value; seeSyntaxFactory.KeyandSyntaxFactory.Value.
IniProperty(string, string, IniParseOptions)
SyntaxFactory.csCreates 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
keystringvaluestringoptionsIniParseOptions
Returns
Exceptions
ArgumentNullException- An argument is
null. ArgumentExceptionkeycannot be written as a key, orvalueas a value underoptions; seeSyntaxFactory.KeyandSyntaxFactory.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.cspublic static IniSectionSyntax IniSection(SyntaxToken openBracketToken, SyntaxToken nameToken, SyntaxToken closeBracketToken)No documentation is available.
IniSection(string)
SyntaxFactory.csCreates a section header such as [database], ending with a line feed like every line of a document.
public static IniSectionSyntax IniSection(string name)Parameters
namestring
Returns
Exceptions
ArgumentNullExceptionnameisnull.ArgumentExceptionnamecannot be written as a section name; seeSyntaxFactory.SectionName.
IniSection(string, IniParseOptions)
SyntaxFactory.csCreates 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
namestringoptionsIniParseOptions
Returns
Exceptions
ArgumentNullExceptionnameoroptionsisnull.ArgumentExceptionnamecannot be written as a section name; seeSyntaxFactory.SectionName.
IniSkippedText overloads
IniSkippedText(SyntaxTokenList)
SyntaxFactory.cspublic static IniSkippedTextSyntax IniSkippedText(SyntaxTokenList tokens)No documentation is available.
IniSkippedText(string)
SyntaxFactory.cspublic static IniSkippedTextSyntax IniSkippedText(string text)Key overloads
Key(string)
SyntaxFactory.csCreates a key token written exactly as text.
public static SyntaxToken Key(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextwould 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.csCreates a key token written exactly as text, for a document read with options.
public static SyntaxToken Key(string text, IniParseOptions options)Parameters
textstringoptionsIniParseOptions
Returns
Exceptions
ArgumentNullExceptiontextoroptionsisnull.ArgumentExceptiontextwould not read back as this key underoptions: 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.cspublic static SyntaxList<TNode> List<TNode>() where TNode : IniSyntaxNodeNo documentation is available.
List<TNode>(IEnumerable<TNode>)
SyntaxFactory.cspublic static SyntaxList<TNode> List<TNode>(IEnumerable<TNode> nodes) where TNode : IniSyntaxNodeType parameters
TNode
Parameters
nodesIEnumerable<TNode>
Returns
Exceptions
ArgumentNullExceptionnodesisnull.
MissingToken(SyntaxKind)
SyntaxFactory.csCreates a zero-width token standing in for one the text does not have.
public static SyntaxToken MissingToken(SyntaxKind kind)ParseDocument overloads
ParseDocument(string)
SyntaxFactory.csParses text and returns its root.
public static IniDocumentSyntax ParseDocument(string text)ParseDocument(string, IniParseOptions?)
SyntaxFactory.csParses text and returns its root.
public static IniDocumentSyntax ParseDocument(string text, IniParseOptions? options)ParseSyntaxTree overloads
ParseSyntaxTree(string, IniParseOptions?, string?)
SyntaxFactory.csParses text into a tree.
public static IniSyntaxTree ParseSyntaxTree(string text, IniParseOptions? options, string? path = null)Parameters
textstringoptionsIniParseOptions?pathstring?
Returns
Exceptions
ArgumentNullExceptiontextisnull.
ParseSyntaxTree(string, string?)
SyntaxFactory.csParses text into a tree.
public static IniSyntaxTree ParseSyntaxTree(string text, string? path = null)RawValue(string)
SyntaxFactory.csCreates a value token written exactly as text, quotes included.
public static SyntaxToken RawValue(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextwould not read back as one value: it has whitespace around it, a line break, or a;or#outside quotes.
SectionName overloads
SectionName(string)
SyntaxFactory.csCreates a section name token written exactly as text.
public static SyntaxToken SectionName(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextwould not read back as this name: it is empty, has whitespace around it, or holds],;,#, or a line break.
SectionName(string, IniParseOptions)
SyntaxFactory.csCreates a section name token written exactly as text, for a document read with options.
public static SyntaxToken SectionName(string text, IniParseOptions options)Parameters
textstringoptionsIniParseOptions
Returns
Exceptions
ArgumentNullExceptiontextoroptionsisnull.ArgumentExceptiontextwould not read back as this name underoptions: 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.cspublic static SyntaxList<TNode> SingletonList<TNode>(TNode node) where TNode : IniSyntaxNodeNo documentation is available.
Token overloads
Token(SyntaxKind)
SyntaxFactory.csCreates a token whose text is fixed by its kind, such as a bracket or separator.
public static SyntaxToken Token(SyntaxKind kind)Token(SyntaxTriviaList, SyntaxKind, SyntaxTriviaList)
SyntaxFactory.csCreates a token with trivia on either side.
public static SyntaxToken Token(SyntaxTriviaList leading, SyntaxKind kind, SyntaxTriviaList trailing)TokenList overloads
TokenList()
SyntaxFactory.csTokenList(SyntaxToken)
SyntaxFactory.cspublic static SyntaxTokenList TokenList(SyntaxToken token)No documentation is available.
TokenList(SyntaxToken[])
SyntaxFactory.cspublic static SyntaxTokenList TokenList(params SyntaxToken[] tokens)No documentation is available.
TokenList(IEnumerable<SyntaxToken>)
SyntaxFactory.cspublic static SyntaxTokenList TokenList(IEnumerable<SyntaxToken> tokens)Trivia(SyntaxKind, string)
SyntaxFactory.csCreates trivia of the given kind.
public static SyntaxTrivia Trivia(SyntaxKind kind, string text)Parameters
kindSyntaxKindtextstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis not trivia of that kind, orkindis not a kind of trivia.
TriviaList overloads
TriviaList()
SyntaxFactory.csTriviaList(SyntaxTrivia)
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(SyntaxTrivia trivia)No documentation is available.
TriviaList(SyntaxTrivia[])
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(params SyntaxTrivia[] trivia)No documentation is available.
TriviaList(IEnumerable<SyntaxTrivia>)
SyntaxFactory.cspublic static SyntaxTriviaList TriviaList(IEnumerable<SyntaxTrivia> trivia)Value overloads
Value(string)
SyntaxFactory.csCreates a value token that reads back as value, in quotes when it has to be.
public static SyntaxToken Value(string value)Parameters
valuestring
Returns
Exceptions
ArgumentNullExceptionvalueisnull.ArgumentExceptionvalueholds 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.csCreates a value token that reads back as value in a document read with options.
public static SyntaxToken Value(string value, IniParseOptions options)Parameters
valuestringoptionsIniParseOptions
Returns
Exceptions
ArgumentNullExceptionvalueoroptionsisnull.ArgumentExceptionvalueholds a line break, or cannot be written so thatoptionsread 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.cspublic static SyntaxTrivia Whitespace(string text)Parameters
textstring
Returns
Exceptions
ArgumentNullExceptiontextisnull.ArgumentExceptiontextis 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.