1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Parse.Declaration
10import qualified Data.Text.Encoding as Text
12import qualified AST.Expression.Source as Src
13import qualified AST.Pattern as Pattern
14import qualified AST.Type as Type
15import qualified Parse.Expression as Expr
16import qualified Parse.Pattern as Pattern
17import Parse.Primitives
18import qualified Parse.Primitives.Keyword as Keyword
19import qualified Parse.Primitives.Symbol as Symbol
20import qualified Parse.Primitives.Variable as Var
21import qualified Parse.Primitives.Whitespace as W
22import qualified Parse.Type as Type
23import qualified Reporting.Annotation as A
24import qualified Reporting.Error.Syntax as E
25import qualified Reporting.Region as R
32declaration :: SParser Src.Decl
35 do start <- getPosition
49doc_ :: R.Position -> SParser Src.Decl
51 do doc <- W.docComment
54 return ( A.at start end (Src.Docs (Text.decodeUtf8 doc)), end, pos )
58-- DEFINITION and ANNOTATION
62def_ :: R.Position -> SParser Src.Decl
65 nameEnd <- getPosition
66 let locatedName = A.at start nameEnd name
70 inContext start (E.Annotation name) $
72 (tipe, end, space) <- Type.expression
73 return ( A.at start end (Src.Annotation locatedName tipe), end, space )
74 , inContext start (E.Definition name) $
75 definitionHelp start locatedName []
79definitionHelp :: R.Position -> A.Located Text -> [Pattern.Raw] -> SParser Src.Decl
80definitionHelp start name revArgs =
82 [ do arg <- hint E.Arg Pattern.term
84 definitionHelp start name (arg : revArgs)
87 (body, end, space) <- Expr.expression
88 let def = A.at start end (Src.Definition name (reverse revArgs) body)
89 return ( def, end, space )
94-- TYPE ALIAS and UNION TYPES
98type_ :: R.Position -> SParser Src.Decl
104 inContext start E.TypeAlias $
106 (name, args) <- nameArgsEquals
107 (tipe, end, pos) <- Type.expression
108 return ( A.at start end (Src.Alias name args tipe), end, pos )
109 , inContext start E.TypeUnion $
110 do (name, args) <- nameArgsEquals
111 (firstCtor, firstEnd, firstSpace) <- Type.unionConstructor
112 (ctors, end, pos) <- chompConstructors [firstCtor] firstEnd firstSpace
113 return ( A.at start end (Src.Union name args ctors), end, pos )
117nameArgsEquals :: Parser (A.Located Text, [A.Located Text])
119 do name <- addLocation Var.upper
121 nameArgsEqualsHelp name []
124nameArgsEqualsHelp :: A.Located Text -> [A.Located Text] -> Parser (A.Located Text, [A.Located Text])
125nameArgsEqualsHelp name args =
127 [ do arg <- addLocation Var.lower
129 nameArgsEqualsHelp name (arg:args)
132 return ( name, reverse args )
136chompConstructors :: [(A.Located Text, [Type.Raw])] -> R.Position -> SPos -> SParser [(A.Located Text, [Type.Raw])]
137chompConstructors ctors end pos =
142 (ctor, newEnd, newSpace) <- Type.unionConstructor
143 chompConstructors (ctor:ctors) newEnd newSpace
144 , return ( reverse ctors, end, pos )
153port_ :: R.Position -> SParser Src.Decl
156 inContext start E.Port $
158 name <- addLocation Var.lower
162 (tipe, end, pos) <- Type.expression
163 return ( A.at start end (Src.Port name tipe), end, pos )
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