Skip to content

Implement stricter parsing to avoid skipping invalid lines #582

@ebeigarts

Description

@ebeigarts

Currently there is no way to fully validate the openui lang, invalid lines are just silently skipped.

https://github.com/thesysdev/openui/blob/main/packages/lang-core/src/parser/statements.ts#L70

  • Invalid lines (no =, or no identifier) are silently skipped.

Example LLM output:

Here is the response:
root = Stack([TextContent("hi")])

Rendered output:

hi

The Here is the response: is just silently skipped and parser also returns 0 errors.

Maybe add parse(input, strict: true) or something like that to get all the errors.

Current workaround:

const parser = createParser(schema)
const result = parser.parse(input)

const lines = input.split("\n")
for (let i = 0; i < lines.length; i++) {
  const trimmed = lines[i].trim()
  if (!trimmed) continue
  if (/^[A-Za-z_$][\w$]*\s*=/.test(trimmed)) break
  const snippet = trimmed.length > 80 ? trimmed.slice(0, 80) + "..." : trimmed
  result.meta.errors.push({
    source: "parser",
    code: "parse-failed",
    message: `Line ${i + 1}: "${snippet}" — not a valid openui-lang statement (expected \`identifier = expression\`)`,
  })
}

The current workaround works for the example above, but will not work for more complicated cases, because openlang can be multiline and that would require full parsing (counting [, (, etc between the lines).

Here is the response:

root = Stack([
  TextContent("hi")
])

Hope this helps!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions