A YAML document parser that converts YAML text into JsonElement model objects. The parser supports block mappings, block sequences, multi-line strings, flow collections, anchors/aliases, and automatic scalar type inference.
YamlParser
01 Syntax
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| Parse | 1 | Parse a YAML document string into a JsonElement model tree. |
| ParseFile | 1 | Parse a YAML document from a file path into a JsonElement model tree. |
| PreProcess | 1 | Pre-process the raw YAML text into a list of logical YamlLine records. |
| CollectQuotedString | 1 | Collect a multi-line quoted string that spans multiple lines. |
| IsQuotedStringClosed | 1 | Check if a string that starts with a quote character has a matching closing quote. |
| NormalizeMultiLineQuotedString | 1 | Normalize a multi-line quoted string by extracting the content between quotes and re-joining it as a single-line string with proper escaping. |
| FinalizeBlockScalar | 1 | Finalize a block scalar (| or >) by joining the collected lines according to the block scalar style. |
| ParseValue | 1 | Parse a value starting at the given line index and indentation level. |
| ParseMapping | 1 | Parse a block mapping (key: value pairs) starting at the given line. |
| ParseSequence | 1 | Parse a block sequence (list items starting with '-') starting at the given line. |
| ParseFlowSequence | 1 | Parse a flow sequence (inline array like [a, b, c]). |
| ParseFlowMapping | 1 | Parse a flow mapping (inline object like {key: value, key2: value2}). |
| SplitFlowItems | 1 | Split a flow collection string by a separator character, respecting nested brackets, braces, and quoted strings. |
| ParseBlockScalarValue | 1 | Parse a block scalar value that has been pre-processed into a single-line representation. |
| CreateScalarValue | 1 | Create a JsonValue from a YAML scalar string, performing type inference. |
| TryParseInteger | 1 | Try to parse a string as an integer (decimal, hex, octal, or binary). |
| UnescapeDoubleQuotedString | 1 | Unescape a double-quoted YAML string content (without surrounding quotes). |
| FindMappingColon | 1 | Find the position of the mapping colon (':') in a line, respecting quoted strings and flow collections. |
| StripComment | 1 | Strip a trailing inline comment from a string, respecting quoted strings. |
| UnquoteString | 1 | Remove surrounding quotes from a string key (single or double quotes). |
| Reset | 1 | Clear all stored anchors. |
03 Fields
| Name | Overloads | Summary |
|---|---|---|
| _anchors | 1 | Dictionary of named anchors for alias resolution. |
04 Members
String)Parse a YAML document string into a JsonElement model tree. If the YAML contains multiple documents separated by '---', only the first document is parsed.
| Name | Type | Description |
|---|---|---|
yamlText | String | The YAML document text. |
The root JsonElement (typically a JsonObject).
String)Parse a YAML document from a file path into a JsonElement model tree.
| Name | Type | Description |
|---|---|---|
filePath | String | The path to the YAML file. |
The root JsonElement (typically a JsonObject).
String)Pre-process the raw YAML text into a list of logical YamlLine records. This handles:
- Stripping comments (outside of quoted strings)
- Joining multi-line block scalars (| and >)
- Joining multi-line quoted strings
- Tracking indentation levels
- Skipping document markers (---, ...) and empty lines
String, String(), Int32, Int32)Collect a multi-line quoted string that spans multiple lines. Returns the complete quoted string (including quotes), or Nothing if the string is complete on a single line.
String, Char)Check if a string that starts with a quote character has a matching closing quote. Handles escaped quotes within the string.
String, Char)Normalize a multi-line quoted string by extracting the content between quotes and re-joining it as a single-line string with proper escaping.
Finalize a block scalar (| or >) by joining the collected lines according to the block scalar style.
List(Of YamlLine), Int32, Int32)Parse a value starting at the given line index and indentation level. Determines the type of value (mapping, sequence, or scalar) and delegates to the appropriate parsing method.
List(Of YamlLine), Int32, Int32)Parse a block mapping (key: value pairs) starting at the given line.
List(Of YamlLine), Int32, Int32)Parse a block sequence (list items starting with '-') starting at the given line.
String)Parse a flow sequence (inline array like [a, b, c]).
String)Parse a flow mapping (inline object like {key: value, key2: value2}).
String, Char)Split a flow collection string by a separator character, respecting nested brackets, braces, and quoted strings.
String)Parse a block scalar value that has been pre-processed into a single-line representation. The format is: |content or >content where content contains embedded newlines.
String)Create a JsonValue from a YAML scalar string, performing type inference. The following types are recognized:
- null (null, Null, NULL, ~)
- boolean (true, false, True, False, TRUE, FALSE)
- integer (decimal, hex 0x..., octal 0o..., binary 0b...)
- double (decimal with point, scientific notation, .inf, -.inf, .nan)
- string (everything else, including quoted strings)
String, Int64)Try to parse a string as an integer (decimal, hex, octal, or binary).
String)Unescape a double-quoted YAML string content (without surrounding quotes). Supports: \\, \", \/, \a, \b, \e, \f, \n, \r, \t, \v, \0, \xNN, \uNNNN, \UNNNNNNNN
String)Find the position of the mapping colon (':') in a line, respecting quoted strings and flow collections. Returns -1 if no mapping colon found. A colon is only a mapping colon if it is followed by a space or end-of-line.
String)Strip a trailing inline comment from a string, respecting quoted strings. Comments start with '#' and continue to the end of the line.
String)Remove surrounding quotes from a string key (single or double quotes).
Clear all stored anchors. Call this before parsing a new document.
Dictionary of named anchors for alias resolution. Key: anchor name, Value: the JsonElement associated with the anchor.