1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Parse.Module where
7import qualified AST.Exposing as Exposing
8import qualified AST.Module as Module
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])
22 Module.Header <$> maybeHeaderDecl <*> chompImports []
29maybeHeaderDecl :: Parser (Maybe Module.HeaderDecl)
37headerDecl :: Parser Module.HeaderDecl
39 do start <- getPosition
40 pushContext start E.Module
43 name <- qualifiedCapVar
45 settings <- effectSettings
46 hint E.Exposing $ keyword "exposing"
48 exports <- exposing exposingEntry
50 docs <- maybeDocComment
51 return (Module.HeaderDecl tag name exports settings docs)
55-- MODULE TAGS - module, effect module, port module
58sourceTag :: Parser Module.SourceTag
65 do start <- getPosition
70 return (Module.Port (R.Region start end))
72 do start <- getPosition
77 return (Module.Effect (R.Region start end))
82-- EFFECTS - where { command = MyCmd }
85effectSettings :: Parser Module.SourceSettings
95 effectSettingsHelp start [entry]
96 , return Module.emptySettings
100effectSettingsHelp :: R.Position -> [(A.Located Text, A.Located Text)] -> Parser Module.SourceSettings
101effectSettingsHelp start entries =
107 effectSettingsHelp start (entry:entries)
111 return (A.at start end entries)
115setting :: Parser (A.Located Text, A.Located Text)
117 do name <- addLocation lowVar
121 tipe <- addLocation capVar
129maybeDocComment :: Parser (A.Located (Maybe Text))
131 do oldEnd <- getPosition
133 newStart <- getPosition
135 [ do doc <- docComment
138 return (A.at newStart end (Just doc))
139 , return (A.at oldEnd newStart Nothing)
147chompImports :: [Module.UserImport] -> Parser [Module.UserImport]
148chompImports imports =
150 [ do start <- getPosition
152 pushContext start E.Import
154 name <- qualifiedCapVar
158 [ do checkFreshLine pos
159 let userImport = method start end name Nothing Exposing.closed
161 chompImports (userImport:imports)
164 [ chompAs start name imports
165 , chompExposing start name Nothing imports
168 , return (reverse imports)
172chompAs :: R.Position -> Text -> [Module.UserImport] -> Parser [Module.UserImport]
173chompAs start name imports =
180 [ do checkFreshLine pos
181 let userImport = method start end name (Just alias) (Exposing.Explicit [])
183 chompImports (userImport:imports)
185 chompExposing start name (Just alias) imports
189chompExposing :: R.Position -> Text -> Maybe Text -> [Module.UserImport] -> Parser [Module.UserImport]
190chompExposing start name maybeAlias imports =
191 do keyword "exposing"
193 exposed <- exposing exposingEntry
196 let userImport = method start end name maybeAlias exposed
198 chompImports (userImport:imports)
201method :: R.Position -> R.Position -> Text -> Maybe Text -> Exposing.Raw -> Module.UserImport
202method start end name maybeAlias exposed =
203 A.at start end ( name, Module.ImportMethod maybeAlias exposed )
210exposing :: Parser a -> Parser (Exposing.Exposing a)
221 , do value <- addLocation parser
223 exposingHelp parser [value]
227exposingHelp :: Parser a -> [A.Located a] -> Parser (Exposing.Exposing a)
228exposingHelp parser values =
232 value <- addLocation parser
234 exposingHelp parser (value:values)
236 return (Exposing.Explicit (reverse values))
240exposingEntry :: Parser Exposing.Entry
243 [ Exposing.Lower <$> lowVar
247 return (Exposing.Lower op)
250 Exposing.Upper name <$>
252 [ Just <$> exposing capVar
262freshLine :: Parser ()
264 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