Repository navigation
feat(parser): expose structured parse errors (parse_structured + Error.to_map) - #363
Merged
Merged
Conversation
…r.to_map)
Tooling that wants to render parse errors in its own UI had to either
scrape parse/1's formatted string or match parse_raw/1's internal tuples.
Neither is a stable contract.
- Lua.Parser.Error.to_map/1,2 emits a wire-safe map with the same shape
as Lua.VM.ErrorFormatter.to_map/3, so runtime and parse errors share one
renderer. pointer_column is derived from the real position.column.
- Lua.Parser.parse_structured/1 returns {:ok, Chunk} | {:error, [%Error{}]}.
- parse/1 and parse_structured/1 share parse_to_error/1 so the display and
structured paths cannot drift.
Closes #361
- Reword to_map/2 docs: "leading/trailing whitespace is trimmed" to match clean/1's String.trim/1 behavior. - Drop "| nil" from the doc's source_context.pointer_column; it is always a pos_integer when source_context is present. - Note build_source_context deliberately mirrors ErrorFormatter's windowing. - Add a test pinning source_context (and lines[] element) keys against Lua.VM.ErrorFormatter.to_map/3, not just the top-level keys.
This was referenced Jun 15, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #361.
Lua.Parsercomputed rich, structured error data internally but only exposed it as a pre-formatted ANSI display string. Tooling that renders parse errors in its own UI (editors, LSPs, web frontends) had to either scrape that string or matchparse_raw/1's raw internal tuples — neither a stable contract. This exposes the structured data directly.Changes
Lua.Parser.parse_structured/1→{:ok, Chunk.t()} | {:error, [%Lua.Parser.Error{}]}. Returns the converted error struct(s) instead of a display string. The list shape leaves room for multi-error recovery without a future breaking change.parse/1andparse_structured/1now share a privateparse_to_error/1, so the display and structured paths cannot drift.Lua.Parser.Error.to_map/1and/2— a JSON-serializable map with the same wire shape asLua.VM.ErrorFormatter.to_map/3(type,message,source,line,call_stack,source_context: %{lines, pointer_column},suggestion,error_kind), so runtime and parse errors can flow through a single renderer. Trailing newlines from the internal templates are trimmed; no ANSI escapes appear in any field. A named@type wire_errorpins the shape for dialyzer.Bonus (proposal item 3):
source_context.pointer_columnis populated from the realposition.column, so the^marker lands on the offending token instead of always column 1.Deliberately out of scope
parse_raw/1unchanged — repurposing it would break its existing{:error, term()}contract.Lua.parse_chunk_structured/1— that path also folds in compiler string-errors; separable and messier. TheLua.Parser-level API is the clean primitive.relatederrors omitted from the wire map — never populated today, and including them would diverge fromErrorFormattershape parity.Verification
error_to_map_test.exsandparse_structured_test.exs), 7 skipped.mix dialyzer: 0 errors.mix formatclean.Lua.VM.ErrorFormatter.to_map/3.🤖 Generated with Claude Code