Skip to content
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

Parser: work on NAppDef & OperatorInfo related code #1047

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
eaca311
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
f361fea
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
5741973
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
43c55ac
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
11fdadb
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
18c9c03
Value.Equal: compateAttrSetsM: refactor into lambda
Anton-Latukha Jan 24, 2022
a9aa57a
Value.Equal: isDerivationM: refactor
Anton-Latukha Jan 24, 2022
0a1e05f
hlint: advise traverse
Anton-Latukha Jan 24, 2022
2be2103
hlint: stop advising for{,M}{,_}, use traverse{,_}
Anton-Latukha Jan 24, 2022
058a74a
treewide: stop using for{,M}{,_}, use traverse{,_}
Anton-Latukha Jan 24, 2022
5c8f1f6
Lint: add & use mkSymbolic1
Anton-Latukha Jan 24, 2022
f7d1519
Lint: unify: allow any internal type in the context
Anton-Latukha Jan 24, 2022
987093e
Lint: merge: refactor
Anton-Latukha Jan 24, 2022
6af275d
Parser: add & use NOpName
Anton-Latukha Jan 21, 2022
7e7fbae
Parser: add & use NOpPrecedence
Anton-Latukha Jan 21, 2022
a3e3b50
Parser: cast precedence (NOperatorDef->OperatorInfo) directly
Anton-Latukha Jan 21, 2022
8857e52
Parser: NAppDef: rm NAssoc
Anton-Latukha Jan 22, 2022
f8b7fff
Parser: OperatorInfo: ord fields
Anton-Latukha Jan 22, 2022
48d9979
Parser: NOperatorDef: ord fields
Anton-Latukha Jan 22, 2022
42b74b2
Parser: NOperatorDef: ord fields to match OperatorInfo
Anton-Latukha Jan 22, 2022
2cb05cd
Parser: NOperatorDef: start merging OperatorInfo
Anton-Latukha Jan 22, 2022
983e83c
Parser: NOperatorDef: continue merging OperatorInfo
Anton-Latukha Jan 22, 2022
8189482
Parser: refactor get{Unary,Binary,Special}Operator
Anton-Latukha Jan 22, 2022
233315f
Parser: nixSelector: m refactor
Anton-Latukha Jan 22, 2022
91742a8
Parser: opWithLoc: refactor
Anton-Latukha Jan 22, 2022
e701908
Parser: NOperatorDef: use Map
Anton-Latukha Jan 22, 2022
cf5037e
Parser: NOperatorDef: use Map; unify get*Operation
Anton-Latukha Jan 22, 2022
c19cb90
Parser: m refactor
Anton-Latukha Jan 22, 2022
70006a1
Parser: m org
Anton-Latukha Jan 22, 2022
8f0a337
Parser: refactor
Anton-Latukha Jan 22, 2022
5020d41
Parser: m refactor
Anton-Latukha Jan 23, 2022
2d271b5
Parser: m refactor
Anton-Latukha Jan 23, 2022
8fc276d
Parser: NAssoc: NAssoc(None->)
Anton-Latukha Jan 23, 2022
0c0460a
Parser: refactor
Anton-Latukha Jan 23, 2022
701c591
Value.Equal: refactor
Anton-Latukha Jan 24, 2022
d0f9ff3
Value.Equal: compareAttrSetsM: refactor
Anton-Latukha Jan 24, 2022
fc3f327
Parser: add NOp class & instances
Anton-Latukha Jan 26, 2022
d14bcb2
Parser: argExpr: refactor: return Variadic first
Anton-Latukha Jan 26, 2022
066ff49
Parser: m refactor
Anton-Latukha Jan 26, 2022
a249ffe
Parser: refactor: groundwork to rm OperatorInfo: add class NOp
Anton-Latukha Jan 26, 2022
adc2002
Parser: m refactor
Anton-Latukha Jan 26, 2022
d56f340
Value.Equal: compareAttrSets: refactor
Anton-Latukha Jan 26, 2022
667889b
hlint: mapM -> traverse
Anton-Latukha Jan 26, 2022
9aecc9d
Parser: refactor
Anton-Latukha Jan 26, 2022
816e928
Parser: NOperatorDef: rm OperatorInfo use form the data type
Anton-Latukha Jan 26, 2022
00a834c
Parser: m note
Anton-Latukha Jan 26, 2022
a9efefb
mv OperatorInfo: mod (Parser->Pretty)
Anton-Latukha Jan 26, 2022
15cd046
Pretty: rm appOp
Anton-Latukha Jan 26, 2022
cf28a83
Pretty: rm OperatorInfo
Anton-Latukha Jan 26, 2022
0edf6d7
Pretty: (precedenceWrap -> wrap), precedence(Only -> )Wrap
Anton-Latukha Jan 26, 2022
9d98a64
upd ChangeLog
Anton-Latukha Jan 26, 2022
75ed387
treewide: (unless -> when)
Anton-Latukha Jan 26, 2022
e0c13fe
hlint: stop use unless
Anton-Latukha Jan 26, 2022
eb86d91
tests: Main: refactor
Anton-Latukha Jan 26, 2022
f9112ab
Parser: refactor
Anton-Latukha Jan 26, 2022
44f7b5a
Parser: refactor
Anton-Latukha Jan 26, 2022
8273157
Parser: refactor: construct operator parser list
Anton-Latukha Jan 26, 2022
cbb368a
Parser: refactor
Anton-Latukha Jan 26, 2022
d306bdc
Parser: instance NOp NUnaryOp: rm getOpAssoc
Anton-Latukha Jan 26, 2022
cbbf835
Parser: upd class NOp instances
Anton-Latukha Jan 27, 2022
63148eb
Pretty: m refactor
Anton-Latukha Jan 27, 2022
0a98446
Parser: upd NOperatorDef
Anton-Latukha Jan 27, 2022
95ba14b
Pretty: make selectOp & hasAttrOp local
Anton-Latukha Jan 27, 2022
194553c
Pretty: exprFNixDoc: m refactor
Anton-Latukha Jan 27, 2022
2bf9da9
Expr.Types: mv NApp a bit earlier
Anton-Latukha Jan 27, 2022
5d9c7b5
m org
Anton-Latukha Jan 31, 2022
65a1e3f
Utils: inline handlePresence
Anton-Latukha Jan 31, 2022
966f2f1
Utils.Fix1: m clean-up
Anton-Latukha Jan 31, 2022
619832b
Normal: m refactor
Anton-Latukha Jan 31, 2022
e9d9a2f
Parser: m: add current note
Anton-Latukha Jan 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions .hlint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
- "-XTupleSections"
- "-XTypeApplications"
- "-XViewPatterns"
- ignore:
name: Use unless
- ignore:
name: Use head
- ignore:
Expand Down Expand Up @@ -125,19 +127,19 @@
note: Applying this hint would mean that some actions that were being executed previously would no longer be executed.
rhs: orM s
- hint:
lhs: "fmap and (mapM f s)"
lhs: "fmap and (traversable f s)"
note: Applying this hint would mean that some actions that were being executed previously would no longer be executed.
rhs: allM f s
- hint:
lhs: "and <$> mapM f s"
lhs: "and <$> traversable f s"
note: Applying this hint would mean that some actions that were being executed previously would no longer be executed.
rhs: allM f s
- hint:
lhs: "fmap or (mapM f s)"
lhs: "fmap or (traversable f s)"
note: Applying this hint would mean that some actions that were being executed previously would no longer be executed.
rhs: anyM f s
- hint:
lhs: "or <$> mapM f s"
lhs: "or <$> traversable f s"
note: Applying this hint would mean that some actions that were being executed previously would no longer be executed.
rhs: anyM f s
- warn:
Expand Down Expand Up @@ -180,9 +182,6 @@
lhs: forever
note: "'forever' is loosely typed and may hide errors"
rhs: infinitely
- warn:
lhs: "whenM (not <$> x)"
rhs: unlessM x
- warn:
lhs: "unlessM (not <$> x)"
rhs: whenM x
Expand Down Expand Up @@ -950,11 +949,6 @@
name: "Use 'guard' from Relude"
note: "'guard' is already exported from Relude"
rhs: guard
- warn:
lhs: Control.Monad.unless
name: "Use 'unless' from Relude"
note: "'unless' is already exported from Relude"
rhs: unless
- warn:
lhs: Control.Monad.when
name: "Use 'when' from Relude"
Expand Down Expand Up @@ -1141,15 +1135,14 @@
note: "'foldl'' is already exported from Relude"
rhs: "foldl'"
- warn:
lhs: Data.Foldable.forM_
name: "Use 'forM_' from Relude"
note: "'forM_' is already exported from Relude"
rhs: forM_
lhs: forM_ b a
name: "Use 'traverse_'"
rhs: traverse_ a b
- warn:
lhs: Data.Foldable.for_
name: "Use 'for_' from Relude"
lhs: for_ b a
name: "Use 'traverse_'"
note: "'for_' is already exported from Relude"
rhs: for_
rhs: traverse a b
- warn:
lhs: Data.Foldable.sequenceA_
name: "Use 'sequenceA_' from Relude"
Expand All @@ -1161,15 +1154,9 @@
note: "'toList' is already exported from Relude"
rhs: toList
- warn:
lhs: Data.Foldable.traverse_
name: "Use 'traverse_' from Relude"
note: "'traverse_' is already exported from Relude"
rhs: traverse_
- warn:
lhs: Data.Traversable.forM
name: "Use 'forM' from Relude"
note: "'forM' is already exported from Relude"
rhs: forM
lhs: forM b a
name: "Use 'traverse'"
rhs: traverse a b
- warn:
lhs: Data.Traversable.mapAccumL
name: "Use 'mapAccumL' from Relude"
Expand Down Expand Up @@ -2747,3 +2734,13 @@
lhs: "map"
note: "Use `fmap`"
rhs: fmap

- hint:
lhs: "mapM"
note: "Use `traverse`"
rhs: traverse

- hint:
lhs: "unless b"
note: "Use `when not` as it reads intuitively."
rhs: when (not b)
16 changes: 16 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@
* [(link)](https://github.com/haskell-nix/hnix/pull/1046/files) Unify builder `mkNV*` and `NV*` patterns by bidirectional synonyms, a lot of builders `mkNV*` are removed, and merged to `NV*`. e.g. instead of builder `mkNVList`, `NVList` should be used.
* [(link)](https://github.com/haskell-nix/hnix/pull/1046/files) Constraint `NVConstraint f = (Comonad f, Applicative f)` was introduced, in order to unify builder `mkNV*` and `NV*` patterns.

* `Nix.Parser`:
* [(link)](https://github.com/haskell-nix/hnix/pull/1047/files) rm `OperatorInfo`, using `NOperatorDef`. Number of functions changed signatures accordingly:
* In `Nix.Pretty`:
* `NixDoc ann`
* `mkNixDoc`
* `selectOp`
* `hasAttrOp`
* `precedenceWrap`
* `wrapPath`
* In `Nix.Parser`:
* rm `get{App,Unary,Binary,Special}Operator`, currely `NOp` class instances are used instead.

* `Nix.Pretty`:
* [(link)](https://github.com/haskell-nix/hnix/pull/1047/files) rm `appOp`, instead use `appOpDef`.
* [(link)](https://github.com/haskell-nix/hnix/pull/1047/files) `precedenceWrap` behaviour is changed (to be literal to the name), the old behaviour is now a `wrap` function.

## [(diff)](https://github.com/haskell-nix/hnix/compare/0.15.0...0.16.0#files_bucket) 0.16.0

On update problems, please reach out to us. For support refere to: https://github.com/haskell-nix/hnix/issues/984
Expand Down
1 change: 1 addition & 0 deletions hnix.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,7 @@ library
, deriving-compat >= 0.3 && < 0.7
, directory >= 1.3.1 && < 1.4
, exceptions >= 0.10.0 && < 0.11
, extra >= 1.7 && < 1.8
, filepath >= 1.4.2 && < 1.5
, free >= 5.1 && < 5.2
, gitrev >= 1.1.0 && < 1.4
Expand Down
23 changes: 13 additions & 10 deletions main/Repl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -575,16 +575,19 @@ help :: (MonadNix e t f m, MonadIO m)
-> Repl e t f m ()
help hs _ = do
liftIO $ putStrLn "Available commands:\n"
for_ hs $ \h ->
liftIO .
Text.putStrLn .
Prettyprinter.renderStrict .
Prettyprinter.layoutPretty Prettyprinter.defaultLayoutOptions $
":"
<> Prettyprinter.pretty (helpOptionName h) <> space
<> helpOptionSyntax h
<> Prettyprinter.line
<> Prettyprinter.indent 4 (helpOptionDoc h)
traverse_
(\h ->
liftIO .
Text.putStrLn .
Prettyprinter.renderStrict .
Prettyprinter.layoutPretty Prettyprinter.defaultLayoutOptions $
":"
<> Prettyprinter.pretty (helpOptionName h) <> space
<> helpOptionSyntax h
<> Prettyprinter.line
<> Prettyprinter.indent 4 (helpOptionDoc h)
)
hs

options
:: (MonadNix e t f m, MonadIO m)
Expand Down
2 changes: 1 addition & 1 deletion src/Nix/Builtins.hs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ absolutePathFromValue =
let
path = coerce . toString $ ignoreContext ns

unless (isAbsolute path) $ throwError $ ErrorCall $ "string " <> show path <> " doesn't represent an absolute path"
when (not (isAbsolute path)) $ throwError $ ErrorCall $ "string " <> show path <> " doesn't represent an absolute path"
pure path

NVPath path -> pure path
Expand Down
2 changes: 1 addition & 1 deletion src/Nix/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -320,11 +320,11 @@ callFunc fun arg =

fun' <- demand fun
case fun' of
NVClosure _params f -> f arg
NVBuiltin name f ->
do
span <- askSpan
withFrame Info ((Calling @m @(NValue t f m)) name span) $ f arg -- Is this cool?
NVClosure _params f -> f arg
(NVSet _ m) | Just f <- M.lookup "__functor" m ->
(`callFunc` arg) =<< (`callFunc` fun') f
_x -> throwError $ ErrorCall $ "Attempt to call non-function: " <> show _x
Expand Down
2 changes: 1 addition & 1 deletion src/Nix/Expr/Shorthands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mkIf e1 e2 = Fix . NIf e1 e2
mkFunction :: Params NExpr -> NExpr -> NExpr
mkFunction params = Fix . NAbs params

-- | General dot-reference with optional alternative if the jey does not exist.
-- | General dot-reference with optional alternative if the key does not exist.
-- @since 0.15.0
getRefOrDefault :: Maybe NExpr -> NExpr -> Text -> NExpr
getRefOrDefault alt obj = Fix . NSelect alt obj . mkSelector
Expand Down
8 changes: 4 additions & 4 deletions src/Nix/Expr/Types.hs
Original file line number Diff line number Diff line change
Expand Up @@ -594,15 +594,15 @@ data NExprF r
-- environment variable. For example, @<nixpkgs/pkgs>@.
--
-- > NEnvPath "x" ~ <x>
| NApp !r !r
-- ^ Functional application (aka F.A., apply a function to an argument).
--
-- > NApp f x ~ f x
| NUnary !NUnaryOp !r
-- ^ Application of a unary operator to an expression.
--
-- > NUnary NNeg x ~ - x
-- > NUnary NNot x ~ ! x
| NApp !r !r
-- ^ Functional application (aka F.A., apply a function to an argument).
--
-- > NApp f x ~ f x
| NBinary !NBinaryOp !r !r
-- ^ Application of a binary operator to two expressions.
--
Expand Down
Loading