@@ -37,6 +37,7 @@ module Dhall.Syntax (
37
37
, makeFunctionBinding
38
38
, FieldSelection (.. )
39
39
, makeFieldSelection
40
+ , WithComponent (.. )
40
41
41
42
-- ** 'Let'-blocks
42
43
, MultiLet (.. )
@@ -79,9 +80,6 @@ module Dhall.Syntax (
79
80
, linesLiteral
80
81
, unlinesLiteral
81
82
82
- -- * Desugaring
83
- , desugarWith
84
-
85
83
-- * Utilities
86
84
, internalError
87
85
-- `shift` should really be in `Dhall.Normalize`, but it's here to avoid a
@@ -118,7 +116,6 @@ import qualified Data.List.NonEmpty as NonEmpty
118
116
import qualified Data.Text
119
117
import qualified Data.Time as Time
120
118
import qualified Dhall.Crypto
121
- import qualified Dhall.Optics as Optics
122
119
import qualified Lens.Family as Lens
123
120
import qualified Network.URI as URI
124
121
import qualified Prettyprinter as Pretty
@@ -429,6 +426,10 @@ data FieldSelection s = FieldSelection
429
426
makeFieldSelection :: Text -> FieldSelection s
430
427
makeFieldSelection t = FieldSelection Nothing t Nothing
431
428
429
+ -- | A path component for a @with@ expression
430
+ data WithComponent = WithLabel Text | WithQuestion
431
+ deriving (Data , Eq , Generic , Lift , NFData , Ord , Show )
432
+
432
433
{-| Syntax tree for expressions
433
434
434
435
The @s@ type parameter is used to track the presence or absence of `Src`
@@ -644,7 +645,7 @@ data Expr s a
644
645
-- | > Equivalent _ x y ~ x ≡ y
645
646
| Equivalent (Maybe CharacterSet ) (Expr s a ) (Expr s a )
646
647
-- | > With x y e ~ x with y = e
647
- | With (Expr s a ) (NonEmpty Text ) (Expr s a )
648
+ | With (Expr s a ) (NonEmpty WithComponent ) (Expr s a )
648
649
-- | > Note s x ~ e
649
650
| Note s (Expr s a )
650
651
-- | > ImportAlt ~ e1 ? e2
@@ -1464,30 +1465,6 @@ shift d (V x n) (Let (Binding src0 f src1 mt src2 r) e) =
1464
1465
r' = shift d (V x n) r
1465
1466
shift d v expression = Lens. over subExpressions (shift d v) expression
1466
1467
1467
- -- | Desugar all @with@ expressions
1468
- desugarWith :: Expr s a -> Expr s a
1469
- desugarWith = Optics. rewriteOf subExpressions rewrite
1470
- where
1471
- rewrite e@ (With record (key :| [] ) value) =
1472
- Just
1473
- (Prefer
1474
- mempty
1475
- (PreferFromWith e)
1476
- record
1477
- (RecordLit [ (key, makeRecordField value) ])
1478
- )
1479
- rewrite e@ (With record (key0 :| key1 : keys) value) =
1480
- Just
1481
- (Let
1482
- (makeBinding " _" record)
1483
- (Prefer mempty (PreferFromWith e) " _"
1484
- (RecordLit
1485
- [ (key0, makeRecordField $ With (Field " _" (FieldSelection Nothing key0 Nothing )) (key1 :| keys) (shift 1 " _" value)) ]
1486
- )
1487
- )
1488
- )
1489
- rewrite _ = Nothing
1490
-
1491
1468
_ERROR :: String
1492
1469
_ERROR = " \ESC [1;31mError\ESC [0m"
1493
1470
0 commit comments