Skip to content

feat!: val_highlight 1.0.0 — stable API, linear-time grammars, docs - #4

Merged
saminsohag merged 1 commit into
mainfrom
feature/core-1.0
Nov 17, 2026
Merged

saminsohag merged 1 commit into
mainfrom
feature/core-1.0

Conversation

@saminsohag

Copy link
Copy Markdown
Collaborator

Summary

Prepares val_highlight (the core) for 1.0.0: freezes the public API, fixes the engine problems found in the pre-release audit, and brings the docs up to release quality. Version bumped to 1.0.0; the Flutter package and example now depend on val_highlight: ^1.0.0.

This is step 1 of 2. The val_highlight_flutter 1.0 changes (Material split, widget API cleanup) come in a separate PR, opened after this one merges. Please don't publish yet — both packages go to 1.0.0 together.

Breaking changes (all listed with before/after code in docs/upgrading.mdx)

  • HighlightResult.fromBuffers, rawEnds, rawStacks and ScopeTable(), nameId, push are no longer public. Results can be sent between isolates as they are (new isolate_test.dart).
  • IncrementalHighlighter.lastRescannedLines is read-only.
  • BlockRule is abstract base.
  • Operators(chars, {scope}), Annotation({sigil, scope}), Preprocessor({sigil, scope}).
  • LanguageRegistry(languages, {fallback}).
  • Detection.reason is a DetectionReason enum.
  • languages/c.dart no longer exports cKeywords, cTypes, cLiterals, cCommonRules (moved to lib/src/languages/c_family.dart).
  • ValTheme.lookup merges a dotted scope's prefixes, matching the CSS-class output. Checked: no change for any scope in the 8 built-in themes.
  • matchingBracket defaults to the language's EditingSyntax.brackets.

Fixes

  • Quadratic time on long runs of one pattern in 20 languages (e.g. 80,000 # in Swift: 49 s). About 20 patterns fixed with lookbehinds or bounded scans. test/hostile_input_test.dart checks every language on every punctuation character, a letter, a digit, whitespace and the formerly slow units; verified it fails when a fix is reverted.
  • Crash: very long delimiters threw GrammarException; over 1,024 characters they are now plain text.
  • Memory: one compiled state was cached forever per distinct heredoc tag / fence (3.7 GB for 200k); now at most 64 per grammar (+38 MB).
  • LanguageRegistry.add listed a language twice when added twice.

Highlighting is slightly stricter in a few spots to stay linear (Markdown link text without [, inline HTML tags without <, C++ attributes without [, $name( not a call in C-like languages, capped JS regex literals). All listed in the CHANGELOG.

Docs

  • New pages: Upgrading to 1.0, Streaming text, Platforms and versions, Troubleshooting (added to docs/site.json).
  • Writing a grammar: capture-group behavior, "Keeping it linear"; removed the incorrect "named capture groups are not allowed".
  • US spelling throughout (docs, READMEs, and the doc comments the API pages are generated from).
  • Benchmark numbers from one fresh run, consistent across performance.mdx and the READMEs.
  • API docs regenerated; the generator now handles enums.
  • Every new code sample is covered by the engine and Flutter snippet tests.

Related issue

None found.

Checklist

  • just check passes (format, analyze, tests on the VM and JavaScript)
  • Tests added or updated — a fixed bug gets a regression test
  • Golden snapshots: no changes
  • Breaking changes called out above
  • CHANGELOG.md: val_highlight has its ## 1.0.0 entry (the version is bumped here, as scripts/release.sh expects); val_highlight_flutter has an ## Unreleased note
  • Docs updated

Verification

  • just check: 484 VM and 372 JavaScript core tests, 96 Flutter tests and the example test pass; analyzer clean.
  • just sweep over about 20,000 real files (Flutter SDK + pub cache): 0 errors, 0 scanner mismatches, 0 incremental mismatches, 0 slow files. Its 2 unclosed-region flags also appear on main.
  • gpt_markdown against this core: analyzer clean, same 2042 passing tests as with published 0.1.1. Its 9 failing RTL tests fail identically on 0.1.1 (Flutter 3.50), so they are unrelated.

Benchmarks

just bench-languages, Apple M5, Flutter 3.44.2: 43.0 MB/s before, 42.2–43.4 MB/s after (run-to-run noise). just bench: 9,600 lines in 14.4 ms; one keystroke 0.4 ms.

Freeze the core API for 1.0 and fix the engine problems an audit found.

Breaking (see docs/upgrading.mdx):
- HighlightResult.fromBuffers, rawEnds and rawStacks, and ScopeTable's
  constructor, nameId and push are no longer public.
- IncrementalHighlighter.lastRescannedLines is read-only.
- BlockRule is an abstract base class.
- Operators takes its characters as required and scope by name;
  Annotation and Preprocessor take sigil and scope by name.
- LanguageRegistry takes fallback by name.
- Detection.reason is a DetectionReason enum.
- languages/c.dart no longer exports the shared C lists.
- ValTheme.lookup merges a dotted scope's prefixes, matching the CSS
  classes (no change for the built-in themes).
- matchingBracket defaults to the language's brackets.

Fixed:
- Quadratic time on long runs of one pattern in 20 languages (80,000 `#`
  took 49 s in Swift). test/hostile_input_test.dart now checks every
  language on every punctuation character and the patterns that were
  slow.
- GrammarException on very long delimiters; delimiters over 1,024
  characters are plain text.
- Unbounded memory from caching one state per distinct heredoc tag or
  fence; at most 64 are kept per grammar.
- LanguageRegistry.add listed a language twice.

Docs: upgrade guide, streaming text, platforms and versions,
troubleshooting; capture-group and linear-time guidance for grammar
authors; US spelling; benchmark numbers from one fresh run. Every new
sample is covered by the snippet tests.
@saminsohag
saminsohag merged commit 35116d9 into main Nov 17, 2026
1 check passed
@saminsohag
saminsohag deleted the feature/core-1.0 branch November 17, 2026 15:15
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