-
Notifications
You must be signed in to change notification settings - Fork 145
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
Misc refactors to the Elm compiler's parser integration code #748
Misc refactors to the Elm compiler's parser integration code #748
Conversation
The source name is never really used, and removing it simplifies the code _a lot_.
The refactored types are optimized for aiding in debugging instead of providing user friendly error messages.
errorPos err = | ||
case err of | ||
Nil -> | ||
error "An unexpeced error occured, this is likely a bug. Please report this issue at https://github.com/avh4/elm-format/issues" |
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.
errorPos
crashes on empty error. I realize that it's possible to define ParseError
to make impossible state impossible. But since Nil isn't exposed outside this module and since it's never used to construct an empty error I figured this was ok. That said I'm not opposed to changing this
This all looks good. And some of these were pretty big cleanups -- thanks! |
Misc refactors to the Elm compiler's parser integration code
Apart from small changes and improvements there is one notable refactors in this PR
Refactor the parsec adapter's error type
elm-format doesn't report errors anyways, why care?
Parsec errors are essentially strings with some additional metadata. The Elm compiler on the other hand defines all possible parse errors as custom types inside
Reporting.Error.Syntax
. With this approach no information is lost when a parse error is propagated from the lowest level parser through the higher level ones. The higher level ones just construct higher level errors with the lower level errors as children.393c7ee redefines parsecs error type. Instead of a single string with metadata it's now possible to create a tree structure, kind of like a generic/untyped version of the Elm compilers errors, it looks like this:
elm-format/elm-format-lib/src/Parse/ParsecAdapter.hs
Lines 348 to 351 in 393c7ee
elm-format/elm-format-lib/src/Parse/ParsecAdapter/Message.hs
Lines 4 to 7 in 393c7ee
9770e47 Integrates the parsec errors with the Elm compilers errors. Additional leaf variants are added to
Message
so that the error types from the compiler parsing code can be added as children to a parsec error without first needing to convert to a string.What the
Message
type looks like now: (note thatString
,Char
andNumber
refer to custom error types)elm-format/elm-format-lib/src/Reporting/Error/Syntax.hs
Lines 105 to 111 in 9770e47