1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Parse.Type (expression, unionConstructor) where
7import qualified AST.Type as Type
8import qualified AST.Variable as Var
10import qualified Reporting.Annotation as A
11import qualified Reporting.Error.Syntax as E
12import qualified Reporting.Region as R
19term :: Parser Type.Raw
22 do start <- getPosition
35variable :: R.Position -> Parser Type.Raw
39 return (A.at start end (Type.RVar var))
46expression :: SParser Type.Raw
49 do start <- getPosition
50 (tipe1, end1, pos1) <-
53 , (,,) <$> term <*> getPosition <*> whitespace
59 (tipe2, end2, pos2) <- expression
60 let tipe = A.at start end2 (Type.RLambda tipe1 tipe2)
61 return ( tipe, end2, pos2 )
62 , return ( tipe1, end1, pos1 )
70constructor :: Parser Type.Raw
73 fmap (Type.RType . Var.Raw) qualifiedCapVar
76app :: R.Position -> SParser Type.Raw
78 do ctor <- constructor
79 ctorEnd <- getPosition
81 (args, end, pos) <- eatArgs [] ctorEnd ctorPos
84 return ( ctor, end, pos )
89 A.at start end (Type.RApp ctor args)
91 return ( tipe, end, pos )
94unionConstructor :: SParser (Text, [Type.Raw])
97 ctorEnd <- getPosition
98 ctorSpace <- whitespace
99 (args, end, space) <- eatArgs [] ctorEnd ctorSpace
100 return ( (ctor, args), end, space )
103eatArgs :: [Type.Raw] -> R.Position -> SPos -> SParser [Type.Raw]
104eatArgs args end pos =
108 newEnd <- getPosition
109 newSpace <- whitespace
110 eatArgs (arg:args) newEnd newSpace
111 , return ( reverse args, end, pos )
119tuple :: R.Position -> Parser Type.Raw
122 inContext start E.TypeTuple $
126 return (Type.tuple (R.Region start end) [])
128 (tipe, _, pos) <- expression
130 tupleEnding start [tipe]
134tupleEnding :: R.Position -> [Type.Raw] -> Parser Type.Raw
135tupleEnding start tipes =
139 (tipe, _, pos) <- expression
141 tupleEnding start (tipe : tipes)
144 case reverse tipes of
149 return (Type.tuple (R.Region start end) tupleTypes)
157record :: R.Position -> Parser Type.Raw
160 inContext start E.TypeRecord $
165 return (A.at start end (Type.RRecord [] Nothing))
166 , do var <- addLocation lowVar
172 fields <- chompFields [firstField]
174 return (A.at start end (Type.RRecord fields (Just (A.map Type.RVar var))))
177 (tipe, _, nextPos) <- expression
179 fields <- chompFields [(var, tipe)]
181 return (A.at start end (Type.RRecord fields Nothing))
186type Field = ( A.Located Text, Type.Raw )
189chompFields :: [Field] -> Parser [Field]
195 chompFields (f : fields)
197 return (reverse fields)
203 do name <- addLocation lowVar
207 (tipe, _, endPos) <- expression
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list