fix(repl): include source location in parse error messages

Parse error messages now include line and column information when
available (e.g., "Parse error [1:5]: Unexpected token") to help users
locate the source of syntax errors more easily.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Claude Bot
2026-01-20 22:23:04 +00:00
parent a1fde6caad
commit 0976fd30ee

View File

@@ -932,10 +932,23 @@ pub const Repl = struct {
const parse_result = transpiler.parse(parse_opts, null) orelse {
// Check for parse errors
if (transpiler.log.errors > 0) {
// Print errors
// Print errors with source location context if available
for (transpiler.log.msgs.items) |msg| {
if (msg.kind == .err) {
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
if (msg.data.location) |loc| {
if (loc.line > 0) {
// Include line and column information
Output.pretty("<red>Parse error<r> <d>[{d}:{d}]<r><red>: {s}<r>\n", .{
loc.line,
loc.column + 1, // Convert 0-based to 1-based
msg.data.text,
});
} else {
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
}
} else {
Output.pretty("<red>Parse error: {s}<r>\n", .{msg.data.text});
}
}
}
transpiler.log.msgs.clearRetainingCapacity();