1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Parse.Module where
7import qualified AST.Module as Module
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
19header :: Parser (Module.Header [Module.UserImport])
21 do start <- getPosition
22 freshLine E.ModuleDecl
26 , Module.defaultHeader start end <$> chompImports []
34fullHeader :: R.Position -> Parser (Module.Header [Module.UserImport])
36 do pushContext start E.Module
39 name <- qualifiedCapVar
41 settings <- effectSettings
42 hint E.Exposing $ keyword "exposing"
44 exports <- listing (addLocation listingValue)
46 docs <- maybeDocComment
47 imports <- chompImports []
48 return (Module.Header tag name exports settings docs imports)
52-- MODULE TAGS - module, effect module, port module
55sourceTag :: Parser Module.SourceTag
62 do start <- getPosition
67 return (Module.Port (R.Region start end))
69 do start <- getPosition
74 return (Module.Effect (R.Region start end))
79-- EFFECTS - where { command = MyCmd }
82effectSettings :: Parser Module.SourceSettings
92 effectSettingsHelp start [entry]
93 , return Module.emptySettings
97effectSettingsHelp :: R.Position -> [(A.Located Text, A.Located Text)] -> Parser Module.SourceSettings
98effectSettingsHelp start entries =
104 effectSettingsHelp start (entry:entries)
108 return (A.at start end entries)
112setting :: Parser (A.Located Text, A.Located Text)
114 do name <- addLocation lowVar
118 tipe <- addLocation capVar
126maybeDocComment :: Parser (A.Located (Maybe Text))
128 do oldEnd <- getPosition
129 freshLine E.DocCommentDecl
130 newStart <- getPosition
132 [ do doc <- docComment
134 freshLine E.ImportDecl
135 return (A.at newStart end (Just doc))
136 , return (A.at oldEnd newStart Nothing)
144chompImports :: [Module.UserImport] -> Parser [Module.UserImport]
145chompImports imports =
147 [ do start <- getPosition
149 pushContext start E.Import
151 name <- qualifiedCapVar
155 [ do checkFreshLine E.ImportDecl pos
156 let userImport = method start end name Nothing Var.closedListing
158 chompImports (userImport:imports)
161 [ chompAs start name imports
162 , chompExposing start name Nothing imports
165 , return (reverse imports)
169chompAs :: R.Position -> Text -> [Module.UserImport] -> Parser [Module.UserImport]
170chompAs start name imports =
177 [ do checkFreshLine E.ImportDecl pos
178 let userImport = method start end name (Just alias) Var.closedListing
180 chompImports (userImport:imports)
182 chompExposing start name (Just alias) imports
186chompExposing :: R.Position -> Text -> Maybe Text -> [Module.UserImport] -> Parser [Module.UserImport]
187chompExposing start name maybeAlias imports =
188 do keyword "exposing"
190 exposed <- listing listingValue
192 freshLine E.ImportDecl
193 let userImport = method start end name maybeAlias exposed
195 chompImports (userImport:imports)
198method :: R.Position -> R.Position -> Text -> Maybe Text -> Var.Listing Var.Value -> Module.UserImport
199method start end name maybeAlias exposed =
200 A.at start end ( name, Module.ImportMethod maybeAlias exposed )
207listing :: Parser a -> Parser (Var.Listing a)
217 return (Var.Listing [] True)
220 listingHelp parser [value]
224listingHelp :: Parser a -> [a] -> Parser (Var.Listing a)
225listingHelp parser values =
231 listingHelp parser (value:values)
233 return (Var.Listing (reverse values) False)
237listingValue :: Parser Var.Value
240 [ Var.Value <$> lowVar
244 return (Var.Value op)
248 [ Var.Union name <$> listing capVar
249 , return (Var.Alias name)
258freshLine :: E.NextDecl -> Parser ()
261 checkFreshLine nextDecl 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