Skip to content

Implement stricter parsing to avoid skipping invalid lines#609

Open
a2Fsa2k wants to merge 1 commit into
thesysdev:mainfrom
a2Fsa2k:feat/strict-parser
Open

Implement stricter parsing to avoid skipping invalid lines#609
a2Fsa2k wants to merge 1 commit into
thesysdev:mainfrom
a2Fsa2k:feat/strict-parser

Conversation

@a2Fsa2k
Copy link
Copy Markdown

@a2Fsa2k a2Fsa2k commented Jun 5, 2026

Summary

Adds strict mode to the openui-lang parser so that invalid lines (lines
that don't match identifier = expression) are reported as parse-failed
errors instead of being silently skipped. Useful for debugging when LLMs
generate preamble text alongside valid openui-lang code.

Changes

  • tokens.ts — Added tokenText() utility to reconstruct text from a token
  • statements.tssplit() now accepts an optional skipped array to
    collect skipped line text
  • parser.ts — Added strict parameter to parse(), and new
    createStrictParser() API that surfaces skipped lines as errors
  • types.ts — Added "parse-failed" to ValidationErrorCode
  • Tests — 5 new test cases for strict mode

Example

const parser = createStrictParser(library.toJSONSchema());
const result = parser.parse('Here is the response:\nroot = Stack([Title("hi")])');
console.log(result.meta.errors);
// [{ code: "parse-failed", message: 'Unexpected text: "Hereistheresponse:" ...' }]

Closes #582

Adds a `createStrictParser()` that reports unexpected text as
parse-failed errors instead of silently skipping it. Useful for
debugging when LLMs generate preamble text alongside valid
openui-lang statements.

Changes:
- Add `tokenText()` utility to reconstruct text from tokens
- `split()` now collects skipped line text when a collector is provided
- Add `createStrictParser()` and `strict` parameter to `parse()`
- Add "parse-failed" to ValidationErrorCode
- Add test coverage for strict mode

Closes thesysdev#582
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.

Implement stricter parsing to avoid skipping invalid lines

1 participant