Add a standalone YAML parser and document editor
This adds hypervel/yaml for applications that read configuration or edit YAML on someone’s behalf. A reader can work with native PHP values. An editor can keep the document structure, including comments, tags, anchors, and scalar styles, while changing an individual value.
For example, a deployment tool can update the replica count without rebuilding the rest of the manifest from a PHP array:
use Hypervel\Yaml\Yaml;
$document = Yaml::parseDocument($manifest)->throwIfInvalid();
$document->set('spec.replicas', 3);
$manifest = $document->toYaml();
For a plain configuration file, Yaml::parse($source) returns the values directly and Yaml::dump($values) writes YAML. The package requires PHP 8.4 and mbstring and can run independently of the framework.
Documents and diagnostics
The document API supports multiple documents in a stream, custom schemas and tags, and traversal of nodes and tokens. A parser diagnostic includes a code and source range. Editors can inspect recoverable errors, and configuration consumers can reject them with throwIfInvalid(). Resource limits bound nesting and alias expansion. Integers outside PHP’s native range retain their exact value.
The implementation derives from eemeli/yaml. The package records the upstream revision and retains its ISC notice. The documentation covers the PHP value conversions, source positions, and editing APIs.
Verification
The YAML suite exercises the parser against the YAML conformance fixtures, JSON edge cases, and workflow manifests. It also covers document round trips, coroutine isolation, and use without the framework autoloader. The fixture files and symlinks retain their original contents.
The package tests, static analysis, and formatting checks passed locally. The PHP and Node benchmark runners were syntax-checked.
[!NOTE]
Add a standalone YAML parser and document editor package
- Adds a complete
Hypervel\Yaml package under src/yaml/src/: a lexer, streaming CST parser, node composer, and Yaml::parse/Yaml::dump entry points with support for YAML 1.1, 1.2 core, JSON, and failsafe schemas
- Provides editable
Document and node types (Mapping, Sequence, Scalar, Pair, Set, OrderedMap, Pairs) with path-based reads and writes, anchor/alias resolution, bounded copy operations, and visitor traversal
- Handles typed scalars exactly:
BigInteger for out-of-range integers, DateTimeImmutable timestamps with sub-microsecond precision, binary base64 tags, and sexagesimal integer/float values
- Preserves presentation on edits — comments, styles, anchors, and source tokens survive value replacement, copy, and dump/parse round trips
- Includes conformance, property-based, coroutine-safety, and standalone-subprocess test suites plus PHP and JavaScript benchmark runners;
composer.json registers the package dependency and autoloading
Macroscope summarized 0bde351.