1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
10import qualified AST.Exposing as Exposing
11import qualified AST.Module as Module
13import qualified Reporting.Annotation as A
14import qualified Reporting.Error.Syntax as E
15import qualified Reporting.Region as R
22header :: Parser (Module.Header [Module.UserImport])
25 Module.Header <$> maybeHeaderDecl <*> chompImports []
32maybeHeaderDecl :: Parser (Maybe Module.HeaderDecl)
40headerDecl :: Parser Module.HeaderDecl
42 do start <- getPosition
43 pushContext start E.Module
46 name <- qualifiedCapVar
48 settings <- effectSettings
49 hint E.Exposing $ keyword "exposing"
51 exports <- exposing exposingEntry
53 docs <- maybeDocComment
54 return (Module.HeaderDecl tag name exports settings docs)
58-- MODULE TAGS - module, effect module, port module
61sourceTag :: Parser Module.SourceTag
68 do start <- getPosition
73 return (Module.Port (R.Region start end))
75 do start <- getPosition
80 return (Module.Effect (R.Region start end))
85-- EFFECTS - where { command = MyCmd }
88effectSettings :: Parser Module.SourceSettings
98 effectSettingsHelp start [entry]
99 , return Module.emptySettings
103effectSettingsHelp :: R.Position -> [(A.Located Text, A.Located Text)] -> Parser Module.SourceSettings
104effectSettingsHelp start entries =
110 effectSettingsHelp start (entry:entries)
114 return (A.at start end entries)
118setting :: Parser (A.Located Text, A.Located Text)
120 do name <- addLocation lowVar
124 tipe <- addLocation capVar
132maybeDocComment :: Parser (A.Located (Maybe Text))
134 do oldEnd <- getPosition
136 newStart <- getPosition
138 [ do doc <- docComment
141 return (A.at newStart end (Just doc))
142 , return (A.at oldEnd newStart Nothing)
150chompImports :: [Module.UserImport] -> Parser [Module.UserImport]
151chompImports imports =
153 [ do start <- getPosition
155 pushContext start E.Import
157 name <- qualifiedCapVar
161 [ do checkFreshLine pos
162 let userImport = method start end name Nothing Exposing.closed
164 chompImports (userImport:imports)
167 [ chompAs start name imports
168 , chompExposing start name Nothing imports
171 , return (reverse imports)
175chompAs :: R.Position -> Text -> [Module.UserImport] -> Parser [Module.UserImport]
176chompAs start name imports =
183 [ do checkFreshLine pos
184 let userImport = method start end name (Just alias) (Exposing.Explicit [])
186 chompImports (userImport:imports)
188 chompExposing start name (Just alias) imports
192chompExposing :: R.Position -> Text -> Maybe Text -> [Module.UserImport] -> Parser [Module.UserImport]
193chompExposing start name maybeAlias imports =
194 do keyword "exposing"
196 exposed <- exposing exposingEntry
199 let userImport = method start end name maybeAlias exposed
201 chompImports (userImport:imports)
204method :: R.Position -> R.Position -> Text -> Maybe Text -> Exposing.Raw -> Module.UserImport
205method start end name maybeAlias exposed =
206 A.at start end ( name, Module.ImportMethod maybeAlias exposed )
213exposing :: Parser a -> Parser (Exposing.Exposing a)
224 , do value <- addLocation parser
226 exposingHelp parser [value]
230exposingHelp :: Parser a -> [A.Located a] -> Parser (Exposing.Exposing a)
231exposingHelp parser values =
235 value <- addLocation parser
237 exposingHelp parser (value:values)
239 return (Exposing.Explicit (reverse values))
243exposingEntry :: Parser Exposing.Entry
246 [ Exposing.Lower <$> lowVar
250 return (Exposing.Lower op)
253 Exposing.Upper name <$>
255 [ Just <$> exposing capVar
265freshLine :: Parser ()
267 checkFreshLine =<< whitespace
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