-
Notifications
You must be signed in to change notification settings - Fork 710
[POC] Support qualified module renamings #7303
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,6 +41,11 @@ data ModuleRenaming | |
-- | Hiding renaming, e.g., @hiding (A, B)@, bringing all | ||
-- exported modules into scope except the hidden ones. | ||
| HidingRenaming [ModuleName] | ||
-- | Qualified renaming, @(qualified P)@, brining all | ||
-- exported modules into scope with P prefix. So if M | ||
-- was provided by the package, it is now in scope as | ||
-- P.M | ||
| QualifiedRenaming ModuleName | ||
deriving (Show, Read, Eq, Ord, Typeable, Data, Generic) | ||
|
||
-- | Interpret a 'ModuleRenaming' as a partial map from 'ModuleName' | ||
|
@@ -54,6 +59,8 @@ interpModuleRenaming (ModuleRenaming rns) = | |
interpModuleRenaming (HidingRenaming hs) = | ||
let s = Set.fromList hs | ||
in \k -> if k `Set.member` s then Nothing else Just k | ||
interpModuleRenaming (QualifiedRenaming prefix) = | ||
\k -> Just (prefix `joinModuleName` k) | ||
|
||
-- | The default renaming, if something is specified in @build-depends@ | ||
-- only. | ||
|
@@ -79,6 +86,8 @@ instance Pretty ModuleRenaming where | |
pretty DefaultRenaming = mempty | ||
pretty (HidingRenaming hides) | ||
= text "hiding" <+> parens (hsep (punctuate comma (map pretty hides))) | ||
pretty (QualifiedRenaming prefix) | ||
= text "qualified" <+> pretty prefix | ||
pretty (ModuleRenaming rns) | ||
= parens . hsep $ punctuate comma (map dispEntry rns) | ||
where dispEntry (orig, new) | ||
|
@@ -109,7 +118,7 @@ moduleRenamingParsec | |
-> m ModuleRenaming | ||
moduleRenamingParsec bp mn = | ||
-- NB: try not necessary as the first token is obvious | ||
P.choice [ parseRename, parseHiding, return DefaultRenaming ] | ||
P.choice [ parseRename, parseHiding, parseQualified, return DefaultRenaming ] | ||
where | ||
cma = P.char ',' >> P.spaces | ||
parseRename = do | ||
|
@@ -121,6 +130,11 @@ moduleRenamingParsec bp mn = | |
P.spaces -- space isn't strictly required as next is an open paren | ||
hides <- bp (P.sepBy mn cma) | ||
return (HidingRenaming hides) | ||
parseQualified = do | ||
_ <- P.string "qualified" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is wrong. It would allow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. some day I will remember that Cabal's parser doesn't actually have a lexer stage before hand 🤣 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nor |
||
P.skipSpaces1 -- no parenthesis after, space required | ||
prefix <- mn | ||
return (QualifiedRenaming prefix) | ||
parseList = | ||
P.sepBy parseEntry cma | ||
parseEntry = do | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module A where | ||
import Prefix.Quxbaz |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
name: QualifiedIncludes | ||
version: 0.1.0.0 | ||
license: BSD3 | ||
author: Edward Z. Yang | ||
maintainer: [email protected] | ||
build-type: Simple | ||
cabal-version: 2.0 | ||
|
||
library impl | ||
build-depends: base | ||
exposed-modules: Foobar, Quxbaz | ||
hs-source-dirs: impl | ||
default-language: Haskell2010 | ||
|
||
library good | ||
build-depends: base, impl | ||
mixins: impl qualified Prefix | ||
exposed-modules: A | ||
default-language: Haskell2010 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Foobar where |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module Quxbaz where |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Setup configure | ||
Configuring QualifiedIncludes-0.1.0.0... | ||
# Setup build | ||
Preprocessing library 'impl' for QualifiedIncludes-0.1.0.0.. | ||
Building library 'impl' for QualifiedIncludes-0.1.0.0.. | ||
Preprocessing library 'good' for QualifiedIncludes-0.1.0.0.. | ||
Building library 'good' for QualifiedIncludes-0.1.0.0.. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Setup configure | ||
Configuring QualifiedIncludes-0.1.0.0... | ||
# Setup build | ||
Preprocessing library 'impl' for QualifiedIncludes-0.1.0.0.. | ||
Building library 'impl' for QualifiedIncludes-0.1.0.0.. | ||
Preprocessing library 'good' for QualifiedIncludes-0.1.0.0.. | ||
Building library 'good' for QualifiedIncludes-0.1.0.0.. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import Test.Cabal.Prelude | ||
main = setupAndCabalTest $ do | ||
skipUnlessGhcVersion ">= 8.1" | ||
setup "configure" [] | ||
setup "build" [] | ||
return () |
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.
Is this an expressivity problem of a framework, or is there an actual ambiguity in the grammar? I might sound like a SPJ, but can you write down the BNF-grammar then (assuming there is munching lexer, so without need to worry about spaces?)
Uh oh!
There was an error while loading. Please reload this page.
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.
Note, these regexes are virtually only documentation of backpack field syntax (re: #4761).
And while
mixin
syntax definition in https://cabal.readthedocs.io/en/3.4/buildinfo-fields-reference.html is technically correct, it goes beyond what I'd consider "human understandable".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.
Ooh, I used a bad turn of phrase here. Ambiguity isn't the right word.
First, here is the EBNF you requested:
OK, now to explain the problem here. The problem I am having with Distribution.Described lies solely in whitespace handling, as I mentioned in #7303 (comment) The problem is that it is only valid to omit the space before requires (RESpaces) if you didn't select the "qualified" production in ModuleRenaming. If you assume that everything is tokenized beforehand, the problem disappears because
M.Nrequires
will properly tokenize as a single module name, while)requires
will tokenize as two tokens.Yes, no excuse for this. I guess now is a good time to nail that issue :)
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.
@phadej Backpack docs exist and landed!