Skip to content

Commit 31c9e99

Browse files
Merge #983: Parser: org, clean-up, refactor, upds, API breakage
* `Parser`: * `(nixExpr -> nixExprAlgebra)`. * `(nixTopLevelForm -> nixExpr)`. * rm `symbol` from export - they are too core - solving them away inside Parser is crucial, while also too simple `symbol x = char x <* whiteSpace` that people can look-it up/infer themselves, `whiteSpace` so far is requires to be exported, until the situation with Windows `\r\n` gets clearer (when the situation would be properly solved - that export would be superfluous). * use of `takeWhile{,1}P`, which strongly optimizes (magnitudes) the according actions in the parser. * module organization. * all other refactors.
2 parents 57a55fd + 63d6463 commit 31c9e99

File tree

15 files changed

+740
-584
lines changed

15 files changed

+740
-584
lines changed

default.nix

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
# , nixos-20.03 # Last stable release, gets almost no updates to recipes, gets only required backports
9494
# ...
9595
# }
96-
, rev ? "20887e4bbfdae3aed6bfa1f53ddf138ee325515e"
96+
, rev ? "9df2cb074d72ea80ac9fd225b29060c8cf13dd39"
9797

9898
, pkgs ?
9999
if builtins.compareVersions builtins.nixVersion "2.0" > 0
@@ -192,8 +192,6 @@ let
192192

193193
semialign = super.semialign_1_2;
194194
relude = super.relude_1_0_0_1;
195-
hnix-store-core = super.hnix-store-core_0_5_0_0;
196-
hnix-store-remote = super.hnix-store-remote_0_5_0_0;
197195

198196
};
199197

hnix.cabal

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ library
432432
, lens-family-core >= 1.2.2 && < 2.2
433433
, lens-family-th >= 0.5.0 && < 0.6
434434
, logict >= 0.6.0 && < 0.7 || >= 0.7.0.2 && < 0.8
435-
, megaparsec >= 7.0 && < 9.1
435+
, megaparsec >= 7.0 && < 9.2
436436
, monad-control >= 1.0.2 && < 1.1
437437
, monadlist >= 0.0.2 && < 0.1
438438
, mtl >= 2.2.2 && < 2.3

src/Nix/Atoms.hs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Data.Binary ( Binary )
1111
import Data.Aeson.Types ( FromJSON
1212
, ToJSON
1313
)
14+
-- 2021-08-01: NOTE: Check the order efficience of NAtom constructors.
1415

1516
-- | Atoms are values that evaluate to themselves.
1617
-- In other words - this is a constructors that are literals in Nix.

src/Nix/Eval.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,12 @@ eval (NList l ) =
151151

152152
eval (NSet NonRecursive binds) =
153153
do
154-
attrSet <- evalBinds False $ desugarBinds (eval . NSet NonRecursive) binds
154+
attrSet <- evalBinds False $ desugarBinds (eval . NSet mempty) binds
155155
toValue attrSet
156156

157157
eval (NSet Recursive binds) =
158158
do
159-
attrSet <- evalBinds True $ desugarBinds (eval . NSet NonRecursive) binds
159+
attrSet <- evalBinds True $ desugarBinds (eval . NSet mempty) binds
160160
toValue attrSet
161161

162162
eval (NLet binds body ) =

src/Nix/Exec.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ currentPos :: forall e m . (MonadReader e m, Has e SrcSpan) => m SrcSpan
141141
currentPos = asks $ view hasLens
142142

143143
wrapExprLoc :: SrcSpan -> NExprLocF r -> NExprLoc
144-
wrapExprLoc span x = Fix $ Fix (NSymAnnF span "<?>") <$ x
144+
wrapExprLoc span x = Fix $ NSymAnn span "<?>" <$ x
145145
{-# inline wrapExprLoc #-}
146146

147147
-- 2021-01-07: NOTE: This instance belongs to be beside MonadEval type class.
@@ -155,7 +155,7 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
155155
scope <- currentScopes
156156
evalError @(NValue t f m) $ SynHole $
157157
SynHoleInfo
158-
{ _synHoleInfo_expr = Fix $ NSynHoleAnnF span name
158+
{ _synHoleInfo_expr = NSynHoleAnn span name
159159
, _synHoleInfo_scope = scope
160160
}
161161

src/Nix/Expr/Shorthands.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ mkRecSet = mkSet Recursive
135135
--
136136
-- > { .. }
137137
mkNonRecSet :: [Binding NExpr] -> NExpr
138-
mkNonRecSet = mkSet NonRecursive
138+
mkNonRecSet = mkSet mempty
139139

140140
-- | General set builder function.
141141
mkSet :: Recursivity -> [Binding NExpr] -> NExpr

src/Nix/Expr/Strings.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ mergePlain (x : xs) = x : mergePlain xs
2222

2323
-- | Remove 'Plain' values equal to 'mempty', as they don't have any
2424
-- informational content.
25-
removePlainEmpty :: [Antiquoted Text r] -> [Antiquoted Text r]
26-
removePlainEmpty = filter f where
25+
removeEmptyPlains :: [Antiquoted Text r] -> [Antiquoted Text r]
26+
removeEmptyPlains = filter f where
2727
f (Plain x) = x /= mempty
2828
f _ = True
2929

@@ -60,7 +60,7 @@ stripIndent [] = Indented 0 mempty
6060
stripIndent xs =
6161
Indented
6262
minIndent
63-
(removePlainEmpty $
63+
(removeEmptyPlains $
6464
mergePlain $
6565
(snd <$>) $
6666
dropWhileEnd

src/Nix/Expr/Types.hs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,12 @@ data Recursivity
448448
, Show, Read, Hashable
449449
)
450450

451+
instance Semigroup Recursivity where
452+
(<>) NonRecursive NonRecursive = NonRecursive
453+
(<>) _ _ = Recursive
454+
455+
instance Monoid Recursivity where
456+
mempty = NonRecursive
451457

452458
-- ** data NUnaryOp
453459

@@ -712,7 +718,7 @@ ekey keys pos f e@(Fix x) | (NSet NonRecursive xs, ann) <- fromNExpr x =
712718
e
713719
(\ v ->
714720
let entry = NamedVar (StaticKey <$> keys) v pos in
715-
Fix $ toNExpr ( NSet NonRecursive $ [entry] <> xs, ann )
721+
Fix $ toNExpr ( NSet mempty $ [entry] <> xs, ann )
716722
)
717723
<$>
718724
f Nothing

src/Nix/Expr/Types/Annotated.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ data SrcSpan = SrcSpan
5656
instance Semigroup SrcSpan where
5757
s1 <> s2 =
5858
SrcSpan
59-
((min `on` spanBegin) s1 s2)
60-
((max `on` spanEnd ) s1 s2)
59+
(on min spanBegin s1 s2)
60+
(on max spanEnd s1 s2)
6161

6262
instance Binary SrcSpan
6363
instance ToJSON SrcSpan
@@ -67,6 +67,7 @@ instance Serialise SrcSpan
6767

6868
-- * data type @Ann@
6969

70+
-- 2021-08-02: NOTE: Annotation needs to be after what is annotated.
7071
-- | A type constructor applied to a type along with an annotation
7172
--
7273
-- Intended to be used with 'Fix':

0 commit comments

Comments
 (0)