feat: add support for ImportQualifiedPost extension#477
Open
ncaq wants to merge 1 commit intohaskell-suite:masterfrom
Open
feat: add support for ImportQualifiedPost extension#477ncaq wants to merge 1 commit intohaskell-suite:masterfrom
ImportQualifiedPost extension#477ncaq wants to merge 1 commit intohaskell-suite:masterfrom
Conversation
I add support for the `ImportQualifiedPost` extension to 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 traditional `import qualified Data.List as L`). Motivation === When tools like the [sandwich](https://github.com/codedownio/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 === - Added `ImportQualifiedPost` to the list of known extensions in `Extension.hs` - Updated the parser grammar to support post-qualified imports by adding a new `optqualified_post` rule - Modified the `ExactPrint` module to correctly handle post-qualified imports by determining the position of the `qualified` keyword based on source locations - Added test cases with golden files to verify correct parsing and exact printing Known 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.
This was referenced Apr 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
ImportQualifiedPostextensionto fix parse errors that occur when processing code that uses this GHC extension.
The extension enables writing import statements with
qualifiedkeyword after the module name(e.g.,
import Data.List qualified as Linstead of the traditionalimport qualified Data.List as L).Motivation
When tools like the sandwich test framework
process Haskell code that uses the
ImportQualifiedPostextension,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
ImportQualifiedPostto the list of known extensions inExtension.hsoptqualified_postruleExactPrintmodule to correctly handle post-qualified imports by determining the position of thequalifiedkeyword 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
ImportDecldata 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
ImportDecldata structure to explicitly track qualification style,but this would require API changes and is out of scope for this implementation.