feat: add support for ImportQualifiedPost
extension
#477
+146
−12
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.
I add support for the
ImportQualifiedPost
extensionto fix parse errors that occur when processing code that uses this GHC extension.
The extension enables writing import statements with
qualified
keyword after the module name(e.g.,
import Data.List qualified as L
instead of the traditionalimport qualified Data.List as L
).Motivation
When tools like the sandwich test framework
process Haskell code that uses the
ImportQualifiedPost
extension,haskell-src-exts was unable to parse these imports correctly, resulting in errors.
This implementation allows code using this extension
to be properly parsed and processed by tools that depend on haskell-src-exts.
Changes
ImportQualifiedPost
to the list of known extensions inExtension.hs
optqualified_post
ruleExactPrint
module to correctly handle post-qualified imports by determining the position of thequalified
keyword based on source locationsKnown Issue
The pretty printer still converts post-qualified imports back to pre-qualified form
(e.g.,
import qualified Data.List as L
)because the
ImportDecl
data structure only stores whether an import is qualified or not,but not whether the qualification is pre or post. This is a limitation of the current API design.
Future improvements could involve modifying the
ImportDecl
data structure to explicitly track qualification style,but this would require API changes and is out of scope for this implementation.