Skip to content

Track lines and columns in error messages#191

Merged
jmmv merged 20 commits intomasterfrom
linecol-in-errors
Oct 24, 2022
Merged

Track lines and columns in error messages#191
jmmv merged 20 commits intomasterfrom
linecol-in-errors

Conversation

@jmmv
Copy link
Copy Markdown
Collaborator

@jmmv jmmv commented Oct 24, 2022

No description provided.

jmmv added 19 commits October 14, 2022 14:18
This extends the CharReader to return CharSpans instead of just
characters so that each returned character can carry the position where
it originally occurred.  This will be used by the lexer to compute
token positions, and in turn deliver better error messages.
This modifies the lexer to wrap Tokens into TokenSpans, which carry
contextual information for the token such as its position and length.
This will be used for more accurate error reporting in the parser.
This is the first pass at modifying the parser to bubble up failing
positions based on the token spans.  The resulting error messages are
better than before, but they are still not super-helpful (because
e.g. they will complain about a WEND missing and point at EOF instead
of at the original WHILE that was problematic).  Improvements will
come separately.
For error messages that highlight unbalanced block closures (ifs, fors,
and whiles), point to the opening keyword instead of the location where
the problem is detected (which may be too late).
Implement Display for Tokens and use that instead of the Debug output
to generate error messages.  These are more user-friendly.
Implement Display for Values and use that instead of the Debug output
to generate error messages.  These are more user-friendly.
This replaces the tuples that represent the various Statement enum
entries in the AST with span structs.  Other than offering better
readability due to named fields, this adds room to track position
information for better error diagnostics.

Note that the builtin call arguments are left untouched, but these
should be spans as well.  I'll do that separately because of the
large implications of this change, as it will impact every single
builtin command.
Instead of passing the flat list of arguments to each Command being
executed, pass the span that defines the command invocation.  This will
allow injecting details about where the invocation is for error purposes
and extend the contents of the arguments to also carry location details.
This modifies the previously-introduced BuiltinCallSpan to carry each
argument in its own ArgSpan.  This will permit propagating positions
for the individual arguments.
This does the same as we did before for statements, but now for
expressions, by adding a new span for almost all expression types.
As a first pass, this leaves literal expressions and symbol
references untouched.
As a continuation of the previous, this finishes the addition of spans
for expressions by adding them for literals and symbol references.
Instead of passing just the list of arguments to the functions, pass
the FunctionCallSpan container to them so that they can get access to
more information.  This is the same that was done for builtin commands.
This allows having different Error/Result types with ease for both
Value computations and Expr evaluations.  The former will not need
to carry a location but the latter will, so we need to start making
them different.
This adds extra information to the multiple Statement spans to track
the positions of the elements that aren't already annotated with one.

Note that these positions track details about elements within the
statement, not the position of the statement itself.  I think this is
fine, given that the later only seems necessary during parsing... but
only time will tell.
ValueErrors do not carry position information, but the caller often has
such details.  By removing the automatic conversions into exec::Errors,
we can catch all the call sites and fix them to annotate the errors.
This prunes more instances of debug dumps into error messages in favor
of more readable text.
This concludes a stream of recent changes to add tracking for lines and
columns to error messages and to clean up a bunch of other details in
them.

Fixes #113.
@jmmv jmmv force-pushed the linecol-in-errors branch from 3333429 to a0de865 Compare October 24, 2022 22:25
@jmmv jmmv merged commit f2e11d6 into master Oct 24, 2022
@jmmv jmmv deleted the linecol-in-errors branch October 24, 2022 22:43
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