NOTE This document was generated by Claude.ai so may have some hallucinations!
VSoft.YAML is implemented as a YAML 1.2 specification compliant parser and writer library. This document details which YAML features are implemented, highlighting differences between YAML 1.1 and YAML 1.2 specifications.
- Specification Compliance
- Core Data Types
- Parsing Features
- Directives Support
- Tag System
- Output Features
- Advanced Features
- YAML 1.1 vs 1.2 Differences
- Extension Features
- Limitations
VSoft.YAML primarily follows the YAML 1.2 specification (revision 1.2.2)
VSoft.YAML provides selective backward compatibility for common YAML 1.1 features:
- Boolean values: Supports
yes/no/on/offfor easier migration - Modern approach: Does not support ambiguous single-letter
y/nbooleans - Numeric formats: Uses YAML 1.2 standards (no ,
0XXoctal prefix), underscores allowed
| Type | Implementation | Examples |
|---|---|---|
| Null | TYAMLValueType.vtNull |
null, ~, empty values |
| Boolean | TYAMLValueType.vtBoolean |
true, false, True, FALSE |
| Integer | TYAMLValueType.vtInteger |
42, -17, 0x2A, 0o52, 0b101010 |
| Float | TYAMLValueType.vtFloat |
3.14, -1.5e10, .inf, -.inf, .nan |
| String | TYAMLValueType.vtString |
hello, "quoted", 'single' |
| Timestamp | TYAMLValueType.vtTimestamp |
2024-01-15T10:30:00Z |
| Type | Implementation | Description |
|---|---|---|
| Mapping | TYAMLValueType.vtMapping |
Key-value pairs {key: value} |
| Sequence | TYAMLValueType.vtSequence |
Ordered lists [a, b, c] |
| Set | TYAMLValueType.vtSet |
Unique values !!set {a, b, c} |
| Type | Implementation | Description |
|---|---|---|
| Alias | TYAMLValueType.vtAlias |
Anchor references *anchor |
The following YAML 1.1 types are not supported per YAML 1.2 specification:
!!pairs- Ordered key-value pairs!!omap- Ordered mapping!!binary- Base64 encoded binary data
- Document markers:
---(start),...(end) - Single document processing: Complete document parsing via
LoadFromString/File/Stream - Multiple document processing: Support for multi-document files via
LoadAllFromString/File/Stream - Comments: Attempts full preservation of comments where possible.
# β
Supported (YAML 1.2 standard)
canonical_true: true
canonical_false: false
uppercase: TRUE
mixed_case: False
# β
Also supported (YAML 1.1 legacy for compatibility)
legacy_yes: yes # Parsed as boolean true
legacy_no: no # Parsed as boolean false
legacy_on: on # Parsed as boolean true
legacy_off: off # Parsed as boolean false
# β Not supported (YAML 1.1 single-letter)
old_y: y # Parsed as string
old_n: n # Parsed as string# β
Supported formats
decimal: 42
hex: 0x2A # Hexadecimal
octal: 0o52 # Octal with 0o prefix
binary: 0b101010 # Binary
float: 3.14159
scientific: 1.5e10
infinity: .inf
negative_infinity: -.inf
not_a_number: .nan
# β Not supported (YAML 1.1 legacy)
old_octal: 052 # Would be parsed as 52, not 42
with_underscores: 1_000_000 # Underscores removed
sexagesimal: 3:25:45 # Base-60 format removed# β
All string formats supported
plain: Hello World
single_quoted: 'Contains "quotes"'
double_quoted: "Contains\nescapes"
literal_block: |
Multi-line
literal text
folded_block: >
Folded into
single line# Block style
- item1
- item2
- item3
# Flow style
[item1, item2, item3]
# Mixed nesting
- [nested, array]
- key: value# Block style
key1: value1
key2: value2
# Flow style
{key1: value1, key2: value2}
# Complex keys (flow style only)
? [complex, key]
: complex value# Define anchor
defaults: &default_config
timeout: 30
retries: 3
# Reference alias
production:
<<: *default_config # β
Merge keys Supported for 1.1 compatibility
host: prod.example.com
# Simple alias reference
backup_config: *default_config # β
SupportedVSoft.YAML supports YAML version directive processing:
%YAML 1.2
---
document: contentSupported Features:
- Version validation: Ensures document compatibility with YAML 1.2
- Multiple version support: Handles YAML 1.1 and 1.2 version directives
- Document header processing: Proper parsing of directive lines
Full support for custom tag handle directives:
%TAG ! tag:example.com,2000:app/
%TAG !! tag:yaml.org,2002:
---
local_tag: !something
standard_tag: !!strSupported Features:
- Custom handle registration: Define custom tag handle prefixes
- URI resolution: Map handles to full URI prefixes
- Standard handle override: Redefine standard
!!handle if needed - Scope: Directives apply to current document only
Usage Examples:
# Custom application tags
%TAG !app! tag:mycompany.com,2024:app/
---
user: !app!user
name: John Doe
role: !app!role adminParsing Behavior:
- Directives must appear before document markers (
---) - Multiple directives of same type override previous declarations
- Invalid directives generate parsing errors with line/column information
- Directive effects are scoped to the current document
Error Handling:
%YAML 1.3 # Error: Unsupported version
%TAG # Error: Invalid TAG directive syntax
%UNKNOWN directive # Warning: Unknown directive ignoredVSoft.YAML provides comprehensive YAML 1.2 tag system support with both parsing and programmatic APIs.
VSoft.YAML supports all YAML 1.2 tag types through the IYAMLTagInfo interface:
# Built-in YAML types
string_value: !!str "42" # Force string type
integer_value: !!int "42" # Parse as integer
null_value: !!null "" # Explicit null
sequence_value: !!seq [a, b] # Explicit sequence
mapping_value: !!map {a: 1} # Explicit mappingSupported Standard Tags:
!!str/!!string- String values!!int/!!integer- Integer values!!float/!!real- Floating-point values!!bool/!!boolean- Boolean values!!null- Null values!!seq- Sequences (arrays)!!map- Mappings (objects)!!set- Sets (unique value collections)!!timestamp- ISO 8601 timestamps
# Application-specific local tags
user_data: !user
name: John
role: !role admin
configuration: !config
timeout: 30%TAG !company! tag:company.com,2024:
---
product: !company!product
name: Widget
version: !company!version 1.0# Full URI tags
timestamp: !<tag:yaml.org,2002:timestamp> 2024-01-15T10:30:00Z
custom_data: !<http://example.com/custom> special_value# Direct URI usage (rarely used)
data: tag:example.com,2024:custom_type valueTag Processing Pipeline:
- Lexical Recognition: Tags identified during tokenization
- Handle Resolution: Custom handles resolved to full URIs via TAG directives
- Type Classification: Tags categorized by type (Standard/Local/Custom/etc.)
- Value Creation: Tagged values created with appropriate type information
Resolution Examples:
%TAG !app! tag:myapp.com,2024:
---
# This tag: !app!user
# Resolves to: tag:myapp.com,2024:user
user_record: !app!user
id: 12345VSoft.YAML provides rich programmatic APIs for working with tags:
// Create values with tags during construction
sequence := doc.Root.AsSequence;
// Add tagged values using string tags
sequence.AddValue('42', '!!int'); // Force integer type
sequence.AddValue('hello', '!!str'); // Force string type
sequence.AddValue(true, '!app!boolean'); // Custom boolean tag
// Add tagged values using IYAMLTagInfo objects
tagInfo := TYAMLTagInfoFactory.CreateStandardTag('float');
sequence.AddValue(3.14, tagInfo);
// Add to mappings with tags
mapping := doc.Root.AsMapping;
mapping.AddOrSetValue('count', 42, '!!int');
mapping.AddOrSetValue('name', 'test', '!app!string');// Modify tags on existing values
value := mapping.Values['count'];
// Set tag using string
value.SetTag('!!str'); // Change to string tag
// Set tag using IYAMLTagInfo object
customTag := TYAMLTagInfoFactory.CreateLocalTag('custom');
value.SetTagInfo(customTag);
// Clear tag (revert to default)
value.ClearTag;// Create different tag types programmatically
standardTag := TYAMLTagInfoFactory.CreateStandardTag('int');
localTag := TYAMLTagInfoFactory.CreateLocalTag('user');
customTag := TYAMLTagInfoFactory.CreateCustomTag('!app!', 'product', 'tag:myapp.com,2024:');
verbatimTag := TYAMLTagInfoFactory.CreateVerbatimTag('http://example.com/custom');
// Parse tags from text
parsedTag := TYAMLTagInfoFactory.ParseTag('!!str');// Validate tag components
isValidHandle := TYAMLTagInfoFactory.IsValidTagHandle('!app!'); // True
isValidSuffix := TYAMLTagInfoFactory.IsValidTagSuffix('user'); // True
isValidURI := TYAMLTagInfoFactory.IsValidTagURI('tag:example.com,2024:test'); // True
// Compare and prioritize tags
priority := TYAMLTagInfoFactory.CompareTagsByPriority(tag1, tag2);
// Get standard type mappings
yamlType := TYAMLTagInfoFactory.GetStandardTagType('str'); // Returns 'string'// Access tag information on any value
if value.HasTag then
begin
tagInfo := value.TagInfo;
// Check tag types
if tagInfo.IsStandardTag then
WriteLn('Standard tag: ' + tagInfo.ResolvedTag);
if tagInfo.IsCustomTag then
WriteLn('Custom tag - Handle: ' + tagInfo.Handle + ', Suffix: ' + tagInfo.Suffix);
// Get tag properties
originalText := tagInfo.OriginalText; // As written in YAML
resolvedURI := tagInfo.ResolvedTag; // Resolved URI form
tagType := tagInfo.TagType; // TYAMLTagType enumeration
end;Tags are preserved and output appropriately based on format settings:
# Input with explicit tags
%TAG !app! tag:myapp.com,2024:
---
users: !!seq
- name: !!str John
age: !!int 25
metadata: !app!userdata
created: 2024-01-15Output behavior:
- Necessary tags: Tags that affect type interpretation are preserved
- Redundant tags: Default type tags may be omitted for cleaner output
- Custom tags: Non-standard tags are always preserved in output
- Format consistency: Tag output respects document formatting (Block/Flow/Mixed)
Recommended Usage:
// Use standard tags for type coercion
mapping.AddOrSetValue('port', '8080', '!!int'); // Ensure integer type
// Use local tags for application-specific types
mapping.AddOrSetValue('user', userData, '!user'); // Application type
// Use custom tags with proper TAG directives for interoperability
// %TAG !myapp! tag:mycompany.com,2024:app/
mapping.AddOrSetValue('product', productData, '!myapp!product');Performance Considerations:
- Tag parsing occurs during value creation
- Tag information is cached in
IYAMLTagInfoobjects - Tag validation is performed once during parsing
- Minimal runtime overhead for tag-aware operations
VSoft.YAML supports multiple output styles via TYAMLOutputFormat:
# Human-readable, indented format
person:
name: John Doe
age: 30
hobbies:
- reading
- coding# Compact, JSON-like format
person: {name: John Doe, age: 30, hobbies: [reading, coding]}# Automatic style selection
person:
name: John Doe
hobbies: [reading, coding] # Flow for simple arrays
address: # Block for complex objects
street: 123 Main St
city: Anytown- Encoding support: UTF-8, ANSI with BOM control
- Indentation control: Configurable indent size
- Quote control: Smart string quoting based on content
- Document markers: Optional
---and...markers - Tag emission: Control explicit type tag output
Complete JSONPath-style querying system:
// Basic queries
matches := doc.Query('$.products[*].name');
// Complex filtering
expensive := doc.Query('$.products[?(@.price > 100)]');
// Recursive descent
authors := doc.Query('$..author');- Precise error reporting: Line and column information
- Parse exceptions:
EYAMLParseExceptionwith context - Path exceptions:
EYAMLPathErrorfor query errors - Type validation: Safe type conversion with error handling
- Interface-based: Automatic reference counting
- No manual cleanup: Managed memory lifecycle
- Thread-safe access: Immutable value semantics
VSoft.YAML provides backward compatibility by supporting both YAML 1.1 and 1.2 boolean formats:
| Input | YAML 1.1 Standard | YAML 1.2 Standard | VSoft.YAML Implementation |
|---|---|---|---|
true |
true |
true |
true β
|
false |
false |
false |
false β
|
yes |
true |
"yes" (string) |
true β
(1.1 compatibility) |
no |
false |
"no" (string) |
false β
(1.1 compatibility) |
on |
true |
"on" (string) |
true β
(1.1 compatibility) |
off |
false |
"off" (string) |
false β
(1.1 compatibility) |
y |
true |
"y" (string) |
"y" (string) β |
n |
false |
"n" (string) |
"n" (string) β |
| Input | YAML 1.1 | YAML 1.2 (VSoft.YAML) |
|---|---|---|
052 |
42 (octal) |
52 (decimal) |
0o52 |
Invalid | 42 (octal) β
|
1_000 |
1000 |
"1_000" (string) |
3:25:45 |
12345 (base-60) |
"3:25:45" (string) |
YAML 1.1 special keys not supported in YAML 1.2:
# β
Merge key (YAML 1.1)
defaults: &defaults
key1: value1
target:
<<: *defaults # Not supported in core YAML 1.2
# β Value key (YAML 1.1)
mapping:
=: special_value # Not supportedYAML 1.1 types removed in YAML 1.2:
!!binaryβ Use string with explicit encoding!!pairsβ Use sequence of mappings!!omapβ Use sequence of single-key mappings
VSoft.YAML provides comprehensive support for YAML files containing multiple documents separated by document markers.
// Load all documents from a string with multiple YAML documents
yamlContent := '---' + sLineBreak +
'document: 1' + sLineBreak +
'title: First Document' + sLineBreak +
'---' + sLineBreak +
'document: 2' + sLineBreak +
'title: Second Document' + sLineBreak +
'...';
documents := TYAML.LoadAllFromString(yamlContent);
WriteLn('Loaded ', Length(documents), ' documents');
for i := 0 to Length(documents) - 1 do
begin
WriteLn('Document ', i + 1, ': ', documents[i].Root.Values['title'].AsString);
end;// Create multiple documents
doc1 := TYAML.CreateMapping;
doc1.AsMapping.AddOrSetValue('name', 'First Document');
doc1.AsMapping.AddOrSetValue('version', 1);
doc2 := TYAML.CreateMapping;
doc2.AsMapping.AddOrSetValue('name', 'Second Document');
doc2.AsMapping.AddOrSetValue('version', 2);
// Write all documents to a single string
SetLength(documents, 2);
documents[0] := doc1;
documents[1] := doc2;
yamlOutput := TYAML.WriteAllToString(documents);
// Output will automatically include document markers (---)Key Features:
- Automatic document markers:
WriteAllToString()automatically adds---markers when multiple documents are present - Document separation: Each document maintains its own options and structure
- File operations:
LoadAllFromFile()andWriteAllToFile()methods support file-based multi-document operations - Mixed document types: Support for documents with different root types (mapping, sequence, set)
// Control document marker output
doc.Options.EmitDocumentMarkers := True; // Force markers even for single documents
doc.Options.EmitDocumentMarkers := False; // Suppress markers (overridden for multiple documents)// Access comments through IYAMLCollection.Comments
mapping := doc.Root.AsMapping;
if mapping.HasComments then
WriteLn('Comments: ' + mapping.Comments.Text);// JSONPath-style queries beyond standard YAML
result := doc.Query('$..price[?(@ > 100)]');// Automatic detection and conversion
hexValue := yamlValue.AsInteger; // Handles 0x, 0o, 0b formats- Automatic UTF-8/ANSI/ASCII detection
- BOM handling for UTF-8 files
- Configurable output encoding
- Sexagesimal (base-60) numbers
- Underscores in numbers
- Old boolean values (
yes,no,on,off, etc.) - Merge keys (
<<) in core schema - Value keys (
=) in mappings
- Schema validation
- Complex key support in block style (only flow style supported)
- Multi-byte Unicode escape sequences beyond
\uXXXXand\UXXXXXXXX
- Multiple document parsing:
TYAML.LoadAllFromString()andTYAML.LoadAllFromFile()methods - Multiple document writing:
TYAML.WriteAllToString()andTYAML.WriteAllToFile()methods - Document boundary handling: Automatic
---markers between documents - Document marker control: Configurable via
EmitDocumentMarkersoption
- Documents are loaded entirely into memory
- Large documents may require significant memory
- Optimized for correctness over maximum speed
VSoft.YAML provides comprehensive YAML 1.2 compliance with selective 1.1 compatibility for practical, real-world YAML processing. The library balances modern standards with backward compatibility:
β
Primary YAML 1.2 specification support
β
JSON compatibility as a proper subset
β
Selective YAML 1.1 boolean compatibility (yes/no/on/off)
β
Complete YAML directive support (%YAML version and %TAG custom handles)
β
Full tag system implementation (Standard, Local, Custom, Verbatim, Global tags)
β
Rich tag-aware programmatic API (Tag creation, modification, and validation)
β
Multiple document support (LoadAllFromString/File, WriteAllToString/File)
β
Predictable type conversion and parsing
β
Rich interface-based API with type safety
β
Advanced querying capabilities via JSONPath
β
Multiple output formats for different use cases
β
Comprehensive test coverage (200+ tests across all features)
This hybrid approach ensures reliable YAML processing that works with both legacy YAML 1.1 documents (using common boolean formats) and modern YAML 1.2 standards, making VSoft.YAML an excellent choice for Delphi applications that need to handle diverse YAML sources while maintaining predictable parsing behavior.