Skip to content
This repository was archived by the owner on Jun 15, 2023. It is now read-only.

Commit 0dfa475

Browse files
committed
Include form field labels in eval
This will allow us to report where errors occur when there are errors in embedded queries, type mismatches for default values, etc.
1 parent fcc5c05 commit 0dfa475

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

src/Text/Markdown/SlamDown/Eval.purs

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ eval
2727
. Monad m
2828
SD.Value a
2929
{ code M.Maybe LanguageId String m a
30-
, textBox SD.TextBox (Const String) m (SD.TextBox Identity)
31-
, value String m a
32-
, list String m (L.List a)
30+
, textBox String SD.TextBox (Const String) m (SD.TextBox Identity)
31+
, value String String m a
32+
, list String String m (L.List a)
3333
}
3434
SD.SlamDownP a
3535
m (SD.SlamDownP a)
@@ -44,48 +44,48 @@ eval fs = everywhereM b i
4444

4545
i SD.Inline a m (SD.Inline a)
4646
i (SD.Code true code) = SD.Code false <<< SD.renderValue <$> fs.code M.Nothing code
47-
i (SD.FormField l r field) = SD.FormField l r <$> f field
47+
i (SD.FormField lbl r field) = SD.FormField lbl r <$> f lbl field
4848
i other = pure $ other
4949

50-
f SD.FormField a m (SD.FormField a)
51-
f (SD.TextBox tb) = SD.TextBox <<< M.fromMaybe tb <$> nbeTextBox tb
50+
f String SD.FormField a m (SD.FormField a)
51+
f lbl (SD.TextBox tb) = SD.TextBox <<< M.fromMaybe tb <$> nbeTextBox tb
5252
where
5353
-- normalization-by-evaluation proceeds by evaluating an object into a semantic model
5454
-- (in this case, `Identity`), and then quoting the result back into the syntax.
5555
nbeTextBox SD.TextBox (Compose M.Maybe SD.Expr) m (M.Maybe (SD.TextBox (Compose M.Maybe SD.Expr)))
5656
nbeTextBox = evalTextBox >>> map (map quoteTextBox)
5757

5858
evalTextBox SD.TextBox (Compose M.Maybe SD.Expr) m (M.Maybe (SD.TextBox Identity))
59-
evalTextBox tb' = T.sequence $ fs.textBox <$> asCode tb' <|> pure <$> asLit tb'
59+
evalTextBox tb' = T.sequence $ fs.textBox lbl <$> asCode tb' <|> pure <$> asLit tb'
6060
where
6161
asLit = SD.traverseTextBox (unwrap >>> (_ >>= SD.getLiteral) >>> map Identity)
6262
asCode = SD.traverseTextBox (unwrap >>> (_ >>= SD.getUnevaluated) >>> map Const)
6363

6464
quoteTextBox SD.TextBox Identity SD.TextBox (Compose M.Maybe SD.Expr)
6565
quoteTextBox = SD.transTextBox (unwrap >>> SD.Literal >>> M.Just >>> Compose)
6666

67-
f (SD.RadioButtons sel opts) = do
68-
sel' ← evalExpr fs.value sel
69-
opts' ← evalExpr fs.list opts
67+
f lbl (SD.RadioButtons sel opts) = do
68+
sel' ← evalExpr lbl fs.value sel
69+
opts' ← evalExpr lbl fs.list opts
7070
pure $ SD.RadioButtons sel' (mergeSelection (L.singleton <$> sel') opts')
7171

72-
f (SD.CheckBoxes sel vals) = do
73-
sel' ← evalExpr fs.list sel
74-
vals' ← evalExpr fs.list vals
72+
f lbl (SD.CheckBoxes sel vals) = do
73+
sel' ← evalExpr lbl fs.list sel
74+
vals' ← evalExpr lbl fs.list vals
7575
pure $ SD.CheckBoxes sel' (mergeSelection sel' vals')
7676

77-
f (SD.DropDown msel opts) = do
78-
msel' ← T.traverse (evalExpr fs.value) msel
79-
opts' ← evalExpr fs.list opts
77+
f lbl (SD.DropDown msel opts) = do
78+
msel' ← T.traverse (evalExpr lbl fs.value) msel
79+
opts' ← evalExpr lbl fs.list opts
8080
pure $ SD.DropDown msel' $ M.maybe opts' (flip mergeSelection opts' <<< map L.singleton) msel'
8181

8282
mergeSelection SD.Expr (L.List a) SD.Expr (L.List a) SD.Expr (L.List a)
8383
mergeSelection (SD.Literal sel) (SD.Literal xs) = SD.Literal $ L.union sel xs
8484
mergeSelection _ exs = exs
8585

86-
evalExpr e. (String m e) SD.Expr e m (SD.Expr e)
87-
evalExpr _ (SD.Literal a) = pure $ SD.Literal a
88-
evalExpr e (SD.Unevaluated s) = SD.Literal <$> e s
86+
evalExpr e. String (String String m e) SD.Expr e m (SD.Expr e)
87+
evalExpr _ _ (SD.Literal a) = pure $ SD.Literal a
88+
evalExpr l e (SD.Unevaluated s) = SD.Literal <$> e l s
8989

9090
getValues e. SD.Expr (L.List e) L.List e
9191
getValues (SD.Literal vs) = vs

test/src/Test/Main.purs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ static = do
238238
$ un ID.Identity
239239
$ SDE.eval
240240
{ code: \_ _ → pure $ SD.stringValue "Evaluated code block!"
241-
, textBox: \t →
241+
, textBox: \_ t →
242242
case t of
243243
SD.PlainText _ → pure $ SD.PlainText $ pure "Evaluated plain text!"
244244
SD.Numeric _ → pure $ SD.Numeric $ pure $ HN.fromNumber 42.0
@@ -251,8 +251,8 @@ static = do
251251
SD.DateTime (prec@SD.Seconds) _ →
252252
pure $ SD.DateTime prec $ pure $
253253
DT.DateTime (unsafeDate 1992 7 30) (unsafeTime 4 52 10)
254-
, value: \_ → pure $ SD.stringValue "Evaluated value!"
255-
, list: \_ → pure $ L.singleton $ SD.stringValue "Evaluated list!"
254+
, value: \_ _ → pure $ SD.stringValue "Evaluated value!"
255+
, list: \_ _ → pure $ L.singleton $ SD.stringValue "Evaluated list!"
256256
} sd
257257
a → a
258258

0 commit comments

Comments
 (0)