-
Notifications
You must be signed in to change notification settings - Fork 40
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error nodes, ParseErrors get source-mapped location #1262
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this is a great cleanup of a many sourcemapping TODOs!
Maybe eventually Hera could import the sourcemap class from Civet so it's no longer duplicated.
Or a separate |
Fixes #1251
(modulo TODOs below)The basic idea is, during
generate
, to translate an"Error"
node into aParseError
object with the current source-mapped location. This only works withsourceMap
enabled, so in some cases I callgenerate
a second time in case of error + no source maps. I also had to tweak the source mapping code to tracksrcLine
andsrcColumn
too. (Early versions of this PR confused the source and output line/column numbers, but this is now resolved.)Now
options.errors
becomes a list ofParseError
objects instead of"Error"
nodes. So far I've just consumed these inmain.civet
when buildingParseErrors
, which now has the array ofParseError
objects, and gives line/column feedback in the CLI ortestCase
.TODO (possibly in future PRs):
Prerequisite:
Relies on DanielXMoore/Hera#18 so tests won't work without
npm link
until that gets released.Examples:
Here's an example of it working in Playground:
Here's an example of it working in VSCode:
Here's an example of it working with Discord bot:
Here's an example of it working in the CLI (improved error display to match Playground and bot):
Other changes:
source/util.civet
to Hera'ssource/sourcemap.civet
. This was left as a TODO. Notably, changed the export fromutil
tosourcemap
.SourceMap
now directly exportedParseError
now exportedisCompileError
checks forParseError
andParseErrors
Civet.compile
witherrors: []
already inoptions
will preventParseErrors
from being thrown. This is important for e.g. the LSP which wants a compiled version in addition to the errors. Previously, you could achieve this behavior only by callingcompile
withast: true
and then callinggenerate
separately.^
instead of just line and column numbers (and no more stack trace)