Skip to content

Add a standalone YAML parser and document editor - #807

Merged
binaryfire merged 6 commits into
0.4from
feature/yaml
Dec 1, 2026
Merged

binaryfire merged 6 commits into
0.4from
feature/yaml

Conversation

@binaryfire

@binaryfire binaryfire commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

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.

View guided diff Turn on auto-fix

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.

Provide native PHP APIs for parsing and emitting YAML streams, editing document nodes, and retaining comments, scalar styles, anchors, and source ranges. Expose schema and tag selection, exact integers, parser diagnostics, and resource limits for native conversion.

Register the standalone component in Composer with PHP and mbstring as its only runtime requirements. Include the upstream ISC notice for code derived from eemeli/yaml.
Exercise the parser and emitter against the YAML conformance suite, JSON edge cases, and workflow documents. Cover source positions, node editing, tag resolution, exact scalar conversion, and round trips through PHP values.

Verify coroutine isolation and standalone operation without the framework autoloader. Preserve fixture bytes, line endings, symlinks, and third-party licenses.
Provide matching workloads for parsing, retained source tokens, document lookup and editing, and single- and multi-document emission. Each runner reports its median operation time and runtime memory measurements.

Document the command-line arguments and load the PHP component directly so the benchmark can run independently of framework bootstrap.
Add the YAML guide to the package index. Explain how to choose between native values and editable documents, customize schemas and tags, retain source information, and interpret diagnostics and resource limits.

Record the upstream revision, source mapping, and PHP-specific behavior alongside the package, with links to the guide and upstream license.
@coderabbitai

coderabbitai Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@binaryfire

Copy link
Copy Markdown
Member Author

@cubic-dev-ai review

@cubic-dev-ai

cubic-dev-ai Bot commented Dec 1, 2026

Copy link
Copy Markdown

@cubic-dev-ai review

@binaryfire cubic can't start this review because your workspace has reached its free monthly review limit. cubic has reviewed 164,098 of the 160,000 allowed lines of code this month. Reviews resume on 10 December 2026 (in 9 days). Paid plans include much higher monthly review limits. Upgrade now to resume reviews.

To help optimise your usage, you can tune cubic to get the most out of your usage limits:

Learn more →

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Add standalone YAML parser and comment-preserving document editor

✨ Enhancement 🧪 Tests 📝 Documentation ⚙️ Configuration changes 🕐 40+ Minutes

Grey Divider

AI Description

• Adds hypervel/yaml, a standalone PHP 8.4 YAML package with a native-value reader and a document
 editor that keeps comments, tags, anchors, and scalar styles.
• Ports eemeli/yaml v3 (pinned revision in UPSTREAM.md) with its ISC notice; adds exact big-integer
 handling, diagnostics with source ranges, and depth and node limits.
• Adds conformance, editing, coroutine-isolation, and standalone-autoload tests, plus PHP and Node
 benchmark runners and the YAML docs.
Merge Risk 🟡 Medium

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • Parsing, conversion, document mutation, and serialization form one bounded library integration: the public Yaml API creates Documents, Documents expose editing and native conversion, and the serializer emits the resulting representation.
  • These are producer and consumer hops of the same end-to-end YAML behavior, not independent functional scopes.
  • The same bounded YAML integration also owns the parse, edit, and emit operations; an exception or resource-limit failure affects the requested operation rather than creating a separate capability.
Behavioral complexity 🔴 High 🧩 Multiple interactions

  • Before: the repository did not contain this Hypervel YAML runtime capability.
  • After: input flows through UTF-8 normalization, lexing, token parsing, composition, schema resolution, node conversion, mutable document editing, alias and anchor handling, and serialization.
  • New correctness conditions include preserving YAML syntax and diagnostics across parser states, resolving YAML 1.1/1.2 and custom-tag compatibility, maintaining node identity and anchors while editing, enforcing depth and node limits, and emitting equivalent values without corrupting comments, styles, or aliases.
  • The parser and composer introduce interacting lexical and document states; the document model introduces mutation and alias invariants; schemas introduce compatibility cases; serialization introduces graph and ordering invariants.
  • These are changed correctness conditions, not complexity inferred merely from helper reuse.
Potential damage 🟡 Medium 🩹 Incorrect results

  • If a parser, schema resolver, document mutation, or serializer regression produces a wrong native value or emitted YAML, callers can consume incorrect configuration or transformed document data.
  • Reverting the package stops new incorrect results, but any already-consumed output must be regenerated by callers; no persistent repository state or external side effect is shown in this PR.
  • Revert restores future library behavior; previously returned or emitted values require caller-side regeneration.
  • No automatic repair worker or persistent-state backfill is present.
Assessed commit 0bde351
Diagram

graph TD
  A["Application code"] --> B["Yaml facade"] --> C["Lexer and CST parser"] --> D["Composer"] --> E["Document and nodes"] --> G["Stringifier"] --> H["YAML output"]
  D --> F["Schema and tags"]
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Use symfony/yaml for parse and dump
  • ➕ Mature, widely used, and small to depend on
  • ➕ Covers the reader use case with less code
  • ➖ Drops comments, anchors, and scalar styles on re-dump
  • ➖ Cannot satisfy the document-editing requirement
2. Wrap the ext-yaml (libyaml) extension
  • ➕ Fast C parser with no PHP port to maintain
  • ➖ Parse-to-native only, with no CST or comment retention
  • ➖ Adds a native extension requirement the package does not have today
3. Ship only the reader and keep editing out of scope
  • ➕ Far less code
  • ➕ Much easier to review and maintain
  • ➖ Does not solve the deployment-tool use case in the description

Recommendation: The port is justified by the round-trip editing requirement. Most PHP YAML libraries parse to native values and cannot keep comments, anchors, or scalar styles on an edit. The PR's approach is reasonable, but the port is a large maintenance surface, so the UPSTREAM.md revision pin and the conformance suite are what keep it honest. Weigh the ongoing sync cost against the reader-only use cases.

Files changed (30) +7206 / -2 · 1 not counted

Enhancement (15) +5451 / -0
Yaml.phpPublic facade: parse, parseDocument, parseDocuments, dump +99/-0

Public facade: parse, parseDocument, parseDocuments, dump

• Entry points that normalize input, run the lexer, CST parser, and composer, and convert to native values or dump. parseDocument attaches a MULTIPLE_DOCS diagnostic when the stream has more than one document.

src/yaml/src/Yaml.php

Document.phpEditable document model with path get, set, and creation helpers +418/-0

Editable document model with path get, set, and creation helpers

• Owns the node graph, schema, directives, and diagnostics. Provides from, createNode, createPair, createAlias, and dot-path get, plus toYaml. Set is described in the PR but its body was not reviewed.

src/yaml/src/Document.php

Parser.phpConcrete syntax tree parser with depth and node limits +1085/-0

Concrete syntax tree parser with depth and node limits

• Ported CST parser constructed with max depth and max node limits, as shown in Yaml.php.

src/yaml/src/Cst/Parser.php

Lexer.phpPorted YAML lexer producing lexemes for the CST parser +642/-0

Ported YAML lexer producing lexemes for the CST parser

• Port of eemeli/yaml's lexer. UPSTREAM.md states offsets address normalized UTF-8 bytes.

src/yaml/src/Parsing/Lexer.php

Composer.phpComposes CST tokens into document nodes and diagnostics +386/-0

Composes CST tokens into document nodes and diagnostics

• Receives tokens from the CST parser and feeds the stream composer, which collects errors and warnings.

src/yaml/src/Parsing/Composer.php

Stringifier.phpSerializes nodes to YAML while preserving scalar styles +760/-0

Serializes nodes to YAML while preserving scalar styles

• Serializes the document node graph back to YAML, mapped from upstream stringify/ per UPSTREAM.md.

src/yaml/src/Serialization/Stringifier.php

Schema.phpCore and YAML 1.1 schemas +305/-0

Core and YAML 1.1 schemas

• Provides core and yaml11 schema factories used by Document::from and parsing.

src/yaml/src/Schema.php

IntegerParser.phpExact integer parsing outside PHP's native int range +217/-0

Exact integer parsing outside PHP's native int range

• Handles integer resolution; the PR states out-of-range integers keep their exact value.

src/yaml/src/Schema/IntegerParser.php

ConversionContext.phpNative value conversion with resource limits +494/-0

Native value conversion with resource limits

• Converts node graphs to PHP values. The PR states depth and alias-expansion limits are enforced here.

src/yaml/src/Nodes/ConversionContext.php

CreateContext.phpBuilds nodes from PHP values with per-operation context +399/-0

Builds nodes from PHP values with per-operation context

• Converts PHP values into nodes for Document::from and createNode, using one creation context per operation.

src/yaml/src/Nodes/CreateContext.php

KeyComparator.phpMapping key comparison +154/-0

Mapping key comparison

• Compares mapping keys; UPSTREAM.md notes array-key collision behavior must be preserved.

src/yaml/src/Nodes/KeyComparator.php

Directives.phpYAML directive parsing and version handling +331/-0

YAML directive parsing and version handling

• Handles YAML directives; UPSTREAM.md notes duplicate directives follow YAML 1.2.2.

src/yaml/src/Parsing/Directives.php

BigInteger.phpArbitrary-precision integer value object +49/-0

Arbitrary-precision integer value object

• Holds integers outside PHP's native range so their exact value is kept.

src/yaml/src/BigInteger.php

Diagnostic.phpParser diagnostic with code and source range +78/-0

Parser diagnostic with code and source range

• Carries a code, message, and source range, as used by parseDocument for MULTIPLE_DOCS.

src/yaml/src/Diagnostic.php

ParseOptions.phpParse options including depth and node limits +34/-0

Parse options including depth and node limits

• Supplies maxDepth and maxNodes to the parser, as used in Yaml.php.

src/yaml/src/Options/ParseOptions.php

Tests (7) +888 / -0
ConformanceTest.phpRuns the YAML conformance fixtures against the parser +159/-0

Runs the YAML conformance fixtures against the parser

• Runs the conformance fixture suite against the parser, per the PR description and commit messages.

tests/Yaml/ConformanceTest.php

DocumentEditingTest.phpTests document editing and round trips +259/-0

Tests document editing and round trips

• Covers node editing and round trips through PHP values, per the commit messages.

tests/Yaml/DocumentEditingTest.php

CoroutineSafetyTest.phpTests coroutine isolation of YAML operations +266/-0

Tests coroutine isolation of YAML operations

• Verifies coroutine isolation, as described in the PR and commit messages.

tests/Yaml/CoroutineSafetyTest.php

BigIntegerTest.phpTests exact preservation of out-of-range integers +58/-0

Tests exact preservation of out-of-range integers

• Covers exact scalar conversion of large integers, per the commit messages.

tests/Yaml/BigIntegerTest.php

YAML conformance fixture corpus not counted

YAML conformance fixture corpus

• Adds upstream conformance cases (in.yaml, expected.json, test.event, and related files), with bytes and symlinks preserved per the commit messages.

tests/Yaml/Fixtures/Conformance/

run.phpPHP benchmark runner for YAML workloads +87/-0

PHP benchmark runner for YAML workloads

• Benchmarks parse, lookup, edit, and emit workloads and reports median time and memory, per the commit messages.

tests/Benchmarks/Yaml/run.php

reference.mjsNode reference benchmark for upstream eemeli/yaml +59/-0

Node reference benchmark for upstream eemeli/yaml

• Runs matching workloads against the upstream JavaScript library for comparison, per the commit messages.

tests/Benchmarks/Yaml/reference.mjs

Documentation (5) +816 / -0
UPSTREAM.mdRecords upstream eemeli/yaml revision and PHP ownership map +29/-0

Records upstream eemeli/yaml revision and PHP ownership map

• Pins the ported revision and maps upstream files to their PHP owners, with rules for updating the port.

src/yaml/UPSTREAM.md

LICENSE.mdPackage license file for derived code +26/-0

Package license file for derived code

• Adds the package license file for the derived code.

src/yaml/LICENSE.md

eemeli-yaml.txtRetained ISC notice for eemeli/yaml +13/-0

Retained ISC notice for eemeli/yaml

• Keeps the upstream ISC notice required for derived code.

src/yaml/licenses/eemeli-yaml.txt

yaml.mdYAML documentation for conversions, positions, and editing +747/-0

YAML documentation for conversions, positions, and editing

• Adds a 747-line guide covering PHP value conversions, source positions, and editing APIs, per the PR description.

src/docs/yaml.md

documentation.mdLinks the YAML docs from the documentation index +1/-0

Links the YAML docs from the documentation index

• Adds one index entry pointing to the new YAML guide.

src/docs/documentation.md

Other (3) +51 / -2
composer.jsonRegisters hypervel/yaml and its PSR-4 namespace +4/-2

Registers hypervel/yaml and its PSR-4 namespace

• Adds hypervel/yaml to the replace map and maps Hypervel\Yaml\ to src/yaml/src/.

composer.json

composer.jsonStandalone package manifest requiring PHP 8.4 and mbstring +42/-0

Standalone package manifest requiring PHP 8.4 and mbstring

• Declares the package's runtime requirements (PHP 8.4 and mbstring, per the PR description) so it can run without the framework.

src/yaml/composer.json

.gitattributesMarks YAML fixtures as binary-safe to preserve bytes +5/-0

Marks YAML fixtures as binary-safe to preserve bytes

• Adds five attribute rules for the YAML fixtures; the commit messages say fixture bytes and line endings are preserved.

.gitattributes

Comment thread src/yaml/src/Cst/Parser.php Resolved
Comment thread src/yaml/src/Document.php Resolved
Comment thread src/yaml/src/Nodes/CreateContext.php Resolved
Comment thread src/yaml/src/Nodes/VisitContext.php Resolved
Comment thread src/yaml/src/Parsing/Composer.php Resolved
Comment thread src/yaml/src/Parsing/Directives.php Resolved
Comment thread src/yaml/src/Schema/Tags/NullTag.php Resolved
@greptile-apps

greptile-apps Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Confidence Score: 5/5 Tier: plusRetriggerView in Greptile

[Medium impact] The reviewed changes appear safe to merge; both numbered findings are fixed and no new blocking issue was found.

Summary

Adds standalone hypervel/yaml with parsing, document editing, schemas, diagnostics, and YAML output.

  • PHP callers can read YAML as values or write values back as YAML.
  • Editors can change parts of a YAML document without rebuilding it.
  • The monorepo exposes the YAML package and explains how to use it.

Reviews (3) · Last reviewed commit: "Keep surviving YAML aliases and syntax e..." · Reviewed by Greptile

Comment thread src/yaml/src/Cst/Parser.php Resolved
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Editing an anchored map breaks aliases ✓ Resolved Bug Correctness
Description
Document::set() uses CreateContext::replace() to replace a collection, but that method carries
metadata forward only when the previous node is a scalar, dropping the collection's anchor. When an
editor replaces target: &a {key: old} with a native array while another entry contains *a, the
alias remains and subsequent toYaml() or toNative() fails validation.


Remediation recommended

2. Native serialization can run without bound ✓ Resolved Bug Reliability
Description
CreateContext::select() repeatedly invokes jsonSerialize() until a schema tag identifies the
result, checking only whether an object identity repeats. If each call returns a fresh unsupported
serializable object, selection never reaches node accounting or another depth check, so maxDepth
and maxNodes do not stop the chain.

Grey Divider

Tip of the day
💡 Did you know, you can pick a display mode instead of tweaking every Display option by hand

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

Keep empty flow items and stream documents when emitting an empty null spelling. Preserve comment boundaries and tag directive prefixes on round trips, remove the orphan comma after a CST edit, and attach parser diagnostics to the document that owns them.

Reserve anchor names against the graph that survives a replacement. Keep reviver writes local to each occurrence, including when a custom scalar contains PHP references. Cover negative sequence indexes, self-references, and naming failures without changing the original document.

Charge omitted entries while reading collections, bound consecutive serialization wrappers, and reuse Unicode column counts for diagnostics on long lines. Use PHP 8.5-safe list lookups and format the JavaScript benchmark runner. Add focused regressions and document the editing and construction behavior.
@binaryfire

Copy link
Copy Markdown
Member Author

The collection replacement now retains its anchor when assigning a native value. Existing aliases and a new self-reference both resolve to the replacement. Anchor reservation still checks the rest of the document before installing the change.

Consecutive JsonSerializable wrappers now respect the construction depth limit. The node budget continues to count the YAML nodes produced.

Comment thread src/yaml/src/Nodes/Anchors.php Resolved
Comment thread src/yaml/src/Parsing/Composer.php Resolved
Reserve names mentioned by surviving aliases when generating an anchor for a shared value. Removing an anchored descendant now leaves a detectable dangling alias, and an editor can still explicitly assign its name to repair the document.

Keep unexpected leading tokens in the concrete document so reconstruction preserves their original order. Attach trailing errors to the open document and report malformed standalone end markers on the stream. Cover recovery beside valid documents and anchor resolution after explicit repair.
@binaryfire
binaryfire merged commit e302a13 into 0.4 Dec 1, 2026
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant