-
Notifications
You must be signed in to change notification settings - Fork 0
/
Model.elm
86 lines (64 loc) · 1.56 KB
/
Model.elm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
module Model exposing (..)
import Expr
exposing
( Expr(..)
, Case(..)
, Name
)
import Block
exposing
( Def(..)
, Block(..)
, BlkContent(..)
)
import BlockExample
import Helper
import Dict
import Mouse
import List.Zipper as Zipper exposing (Zipper)
type alias Model =
{ dragging : Maybe Drag
, hover : Maybe Expr.Indices
, blockData : BlockData
, defs : Dict.Dict Expr.Name Def
, draftExpr : Maybe Expr
, eval : Maybe (Zipper EvalFrame)
}
type Item
= DraftItem Expr.Indices
| LibItem Expr.Name
| LibLiteral
type alias Drag =
{ itemId : Item
, confirmed : Bool
, startPos : Mouse.Position
, currentPos : Mouse.Position
}
type alias EvalFrame =
( Expr, Expr.Indices )
type alias BlockData =
Dict.Dict Name Block
init =
{ dragging = Nothing
, hover = Nothing
, blockData = BlockExample.blockData
, defs = BlockExample.defs
, -- [tmp] hard-coded
draftExpr = Just BlockExample.listEvalEx
, eval = Nothing
}
getBlock : BlockData -> Name -> Block
getBlock bdata name =
case Dict.get name bdata of
Just block ->
block
Nothing ->
Debug.crash <| Helper.unwords [ "Block data missing for", name ]
-- HELPER
mkGetDef : Dict.Dict Expr.Name Def -> Block.GetDef a
mkGetDef defs id handler =
case Dict.get id defs of
Just (Def params rhs) ->
handler params rhs
Nothing ->
Debug.crash ("No matching definition found for " ++ id)