on master help sign in
Move AST.Patterns into the phased expression AST
commit1b6b47a99ca423235cbbb7e3a7b067ffdc7598be authorEvan Czaplicki <evancz@users.noreply.github.com> dateMon 30 Oct 2017, 22:15 (9 years ago) parente55ba2b
4 files changed+89−83
src/AST/Expression/Canonical.hs+58−17 src/AST/Expression/Source.hs+26−6 src/AST/Expression/Valid.hs+5−6 src/AST/Pattern.hs−54
src/AST/Expression/Canonical.hs+58−17
@@ -1,9 +1,15 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
33module AST.Expression.Canonical
4− ( Expr
5− , Expr_(..)
4+ ( Expr, Expr_(..)
65 , Def(..)
6+ -- patterns
7+ , Args(..), Arg(..)
8+ , Match(..)
9+ , Pattern, Pattern_(..)
10+ , Destructors
11+ , Destructor(..)
12+ -- decls
713 , Decl(..)
814 , Module(..)
915 , Alias(..)
@@ -25,7 +31,6 @@ import Data.Text (Text)
2531import qualified AST.Binop as Binop
2632import qualified AST.Literal as Literal
2733import qualified AST.Module.Name as ModuleName
28−import qualified AST.Pattern as Ptrn
2934import qualified AST.Type as Type
3035import qualified AST.Variable as Var
3136import qualified Elm.Name as N
@@ -39,7 +44,7 @@ import qualified Reporting.Region as R
3944
4045
4146type Expr =
42− A.Annotated R.Region Expr_
47+ A.Located Expr_
4348
4449
4550data Expr_
@@ -47,22 +52,25 @@ data Expr_
4752 | VarTopLevel ModuleName.Canonical Name
4853 | VarKernel Name Name
4954 | VarForeign ModuleName.Canonical Name
50− | VarOperator ModuleName.Canonical Name Name
55+ | VarOperator Name ModuleName.Canonical Name
5156 | Literal Literal.Literal
5257 | List [Expr]
58+ | Negate Expr
5359 | Binop Name ModuleName.Canonical Name Expr Expr
54− | Lambda [Ptrn.Canonical] Expr
60+ | Lambda Args Expr
5561 | Call Expr [Expr]
5662 | If [(Expr, Expr)] Expr
57− | Let [Graph.SCC Def] Expr
58− | Case Expr [(Ptrn.Canonical, Expr)]
63+ | Let Def Expr
64+ | LetRec [Def] Expr
65+ | LetDestruct Match Expr Expr
66+ | Case Expr [(Match, Expr)]
5967 | CtorAccess Expr Int
6068 | Accessor Name
6169 | Access Expr Name
62− | Update Expr [(Name, Expr)]
63− | Record [(Name, Expr)]
70+ | Update Expr (Map.Map Name Expr)
71+ | Record (Map.Map Name Expr)
6472 | Unit
65− | Tuple Expr Expr [Expr]
73+ | Tuple Expr Expr (Maybe Expr)
6674 | GLShader Name Name Literal.Shader
6775
6876
@@ -72,21 +80,54 @@ data Expr_
7280
7381data Def =
7482 Def
75− { _let_name :: Text
76− , _let_args :: [A.Located Ptrn.Canonical]
77− , _let_body :: Expr
78− , _let_type :: Maybe (A.Located Type.Canonical)
83+ { _def_name :: A.Located N.Name
84+ , _def_args :: Args
85+ , _def_body :: Expr
86+ , _def_type :: Maybe (A.Located Type.Canonical)
7987 }
8088
8189
8290
91+-- PATTERNS
92+
93+
94+data Args = Args [Arg] Destructors
95+data Arg = Arg Int Pattern
96+
97+data Match = Match Pattern Destructors
98+
99+
100+type Pattern = A.Located Pattern_
101+
102+data Pattern_
103+ = PAnything
104+ | PVar N.Name
105+ | PRecord [N.Name]
106+ | PAlias Pattern N.Name
107+ | PUnit
108+ | PTuple Pattern Pattern (Maybe Pattern)
109+ | PCtor ModuleName.Canonical N.Name [Pattern]
110+ | PList [Pattern]
111+ | PCons Pattern Pattern
112+ | PLiteral Literal.Literal
113+
114+
115+type Destructors = Map.Map N.Name (A.Located Destructor)
116+
117+data Destructor
118+ = DIndex Int Destructor
119+ | DField N.Name Destructor
120+ | DRoot Int
121+
122+
123+
83124-- DECLARATIONS
84125
85126
86127data Decl =
87128 Decl
88− { _top_name :: Text
89− , _top_args :: [A.Located Ptrn.Canonical]
129+ { _top_name :: N.Name
130+ , _top_args :: Args
90131 , _top_body :: Expr
91132 , _top_type :: Maybe (A.Located Type.Canonical)
92133 , _top_deps :: [Var.Global]
src/AST/Expression/Source.hs+26−6
@@ -4,6 +4,7 @@ module AST.Expression.Source
44 ( Expr, Expr_(..)
55 , Decl, Decl_(..)
66 , Def(..)
7+ , Pattern, Pattern_(..)
78 , Module(..)
89 , Import(..)
910 , Effects(..)
@@ -21,7 +22,6 @@ import Data.Text (Text)
2122
2223import qualified AST.Binop as Binop
2324import qualified AST.Literal as Literal
24−import qualified AST.Pattern as Ptrn
2525import qualified AST.Type as Type
2626import qualified Elm.Name as N
2727import qualified Reporting.Annotation as A
@@ -42,11 +42,11 @@ data Expr_
4242 | Op N.Name
4343 | Negate Expr
4444 | Binops [(Expr, A.Located N.Name)] Expr
45− | Lambda [Ptrn.Raw] Expr
45+ | Lambda [Pattern] Expr
4646 | Call Expr [Expr]
4747 | If [(Expr, Expr)] Expr
4848 | Let [A.Located Def] Expr
49− | Case Expr [(Ptrn.Raw, Expr)]
49+ | Case Expr [(Pattern, Expr)]
5050 | Accessor N.Name
5151 | Access Expr N.Name
5252 | Update (A.Located N.Name) [(A.Located N.Name, Expr)]
@@ -62,8 +62,28 @@ data Expr_
6262
6363data Def
6464 = Annotate N.Name Type.Raw
65− | Define N.Name [Ptrn.Raw] Expr
66− | Destruct Ptrn.Raw Expr
65+ | Define (A.Located N.Name) [Pattern] Expr
66+ | Destruct Pattern Expr
67+
68+
69+
70+-- PATTERN
71+
72+
73+type Pattern = A.Located Pattern_
74+
75+
76+data Pattern_
77+ = PAnything
78+ | PVar N.Name
79+ | PRecord [A.Located N.Name]
80+ | PAlias Pattern (A.Located N.Name)
81+ | PUnit
82+ | PTuple Pattern Pattern [Pattern]
83+ | PCtor R.Region (Maybe N.Name) N.Name [Pattern]
84+ | PList [Pattern]
85+ | PCons Pattern Pattern
86+ | PLiteral Literal.Literal
6787
6888
6989
@@ -80,7 +100,7 @@ data Decl_
80100 | Port (A.Located N.Name) Type.Raw
81101 | Docs Text
82102 | Annotation (A.Located N.Name) Type.Raw
83− | Definition (A.Located N.Name) [Ptrn.Raw] Expr
103+ | Definition (A.Located N.Name) [Pattern] Expr
84104
85105
86106
src/AST/Expression/Valid.hs+5−6
@@ -20,7 +20,6 @@ import Data.Text (Text)
2020import qualified AST.Binop as Binop
2121import qualified AST.Expression.Source as Src
2222import qualified AST.Literal as Literal
23−import qualified AST.Pattern as Pattern
2423import qualified AST.Type as Type
2524import qualified Elm.Name as N
2625import qualified Reporting.Annotation as A
@@ -41,11 +40,11 @@ data Expr_
4140 | Op N.Name
4241 | Negate Expr
4342 | Binops [(Expr, A.Located N.Name)] Expr
44− | Lambda [Pattern.Raw] Expr
43+ | Lambda [Src.Pattern] Expr
4544 | Call Expr [Expr]
4645 | If [(Expr, Expr)] Expr
4746 | Let [Def] Expr
48− | Case Expr [(Pattern.Raw, Expr)]
47+ | Case Expr [(Src.Pattern, Expr)]
4948 | Accessor N.Name
5049 | Access Expr N.Name
5150 | Update (A.Located N.Name) [(A.Located N.Name, Expr)]
@@ -60,8 +59,8 @@ data Expr_
6059
6160
6261data Def
63− = Define R.Region N.Name [Pattern.Raw] Expr (Maybe Type.Raw)
64− | Destruct R.Region Pattern.Raw Expr
62+ = Define R.Region (A.Located N.Name) [Src.Pattern] Expr (Maybe Type.Raw)
63+ | Destruct R.Region Src.Pattern Expr
6564
6665
6766
@@ -83,7 +82,7 @@ data Module =
8382 }
8483
8584
86−data Decl = Decl (A.Located N.Name) [Pattern.Raw] Expr (Maybe Type.Raw)
85+data Decl = Decl (A.Located N.Name) [Src.Pattern] Expr (Maybe Type.Raw)
8786data Union = Union (A.Located N.Name) [A.Located N.Name] [(A.Located N.Name, [Type.Raw])]
8887data Alias = Alias (A.Located N.Name) [A.Located N.Name] Type.Raw
8988data Binop = Binop (A.Located N.Name) Binop.Associativity Binop.Precedence N.Name
src/AST/Pattern.hsdeleted−54
@@ -1,54 +0,0 @@
1−{-# OPTIONS_GHC -Wall #-}
2−{-# LANGUAGE OverloadedStrings #-}
3−module AST.Pattern
4− ( Raw
5− , Raw_(..)
6− , Canonical
7− , Canonical_(..)
8− )
9− where
10−
11−
12−import qualified AST.Literal as Literal
13−import qualified AST.Module.Name as ModuleName
14−import qualified Elm.Name as N
15−import qualified Reporting.Annotation as A
16−import qualified Reporting.Region as R
17−
18−
19−
20−-- RAW
21−
22−
23−type Raw = A.Located Raw_
24−
25−
26−data Raw_
27− = RCtor R.Region (Maybe N.Name) N.Name [Raw]
28− | RRecord [A.Located N.Name]
29− | RUnit
30− | RTuple Raw Raw [Raw]
31− | RList [Raw]
32− | RCons Raw Raw
33− | RAlias Raw (A.Located N.Name)
34− | RVar N.Name
35− | RAnything
36− | RLiteral Literal.Literal
37−
38−
39−
40−-- CANONICAL
41−
42−
43−type Canonical = A.Located Canonical_
44−
45−
46−data Canonical_
47− = Ctor ModuleName.Canonical N.Name [Canonical]
48− | Record [N.Name]
49− | Unit
50− | Tuple Canonical Canonical [Canonical]
51− | Alias Canonical N.Name
52− | Var N.Name
53− | Anything
54− | Literal Literal.Literal