1{-# OPTIONS_GHC -Wall -fno-warn-unused-do-bind #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Parse.Module where
5import Control.Monad (guard)
8import qualified AST.Module as Module
9import qualified AST.Variable as Var
11import qualified Reporting.Annotation as A
12import qualified Reporting.Region as R
19header :: Parser (Module.Header [Module.UserImport])
21 do space <- whitespace
22 guard (space == Freshline || space == None)
25 , Module.defaultHeader <$> chompImports []
33fullHeader :: Parser (Module.Header [Module.UserImport])
37 name <- qualifiedCapVar -- TODO <?> "the name of this module"
39 settings <- effectSettings
40 keyword "exposing" -- TODO <?> "something like `exposing (..)` which replaced `where` in 0.17"
42 exports <- listing (addLocation listingValue)
44 docs <- maybeDocComment
45 imports <- chompImports []
46 return (Module.Header tag name exports settings docs imports)
50-- MODULE TAGS - module, effect module, port module
53sourceTag :: Parser Module.SourceTag
60 do start <- getPosition
65 return (Module.Port (R.Region start end))
67 do start <- getPosition
72 return (Module.Effect (R.Region start end))
77-- EFFECTS - where { command = MyCmd }
80effectSettings :: Parser Module.SourceSettings
90 effectSettingsHelp start [entry]
91 , return Module.emptySettings
95effectSettingsHelp :: R.Position -> [(A.Located Text, A.Located Text)] -> Parser Module.SourceSettings
96effectSettingsHelp start entries =
102 effectSettingsHelp start (entry:entries)
106 return (A.at start end entries)
110setting :: Parser (A.Located Text, A.Located Text)
112 do name <- addLocation lowVar
116 tipe <- addLocation capVar
124maybeDocComment :: Parser (Maybe (A.Located Text))
127 [ do doc <- addLocation docComment
138chompImports :: [Module.UserImport] -> Parser [Module.UserImport]
139chompImports imports =
141 [ do start <- getPosition
144 name <- qualifiedCapVar
148 [ do guard (space == Freshline)
149 let userImport = method start end name Nothing Var.closedListing
150 chompImports (userImport:imports)
151 , do checkSpaces space
153 [ chompAs start name imports
154 , chompExposing start name Nothing imports
157 , return (reverse imports)
161chompAs :: R.Position -> Text -> [Module.UserImport] -> Parser [Module.UserImport]
162chompAs start name imports =
169 [ do guard (space == Freshline)
170 let userImport = method start end name (Just alias) Var.closedListing
171 chompImports (userImport:imports)
172 , do checkSpaces space
173 chompExposing start name (Just alias) imports
177chompExposing :: R.Position -> Text -> Maybe Text -> [Module.UserImport] -> Parser [Module.UserImport]
178chompExposing start name maybeAlias imports =
179 do keyword "exposing"
181 exposed <- listing listingValue
184 let userImport = method start end name maybeAlias exposed
185 chompImports (userImport:imports)
188method :: R.Position -> R.Position -> Text -> Maybe Text -> Var.Listing Var.Value -> Module.UserImport
189method start end name maybeAlias exposed =
190 A.at start end ( name, Module.ImportMethod maybeAlias exposed )
197listing :: Parser a -> Parser (Var.Listing a)
199 expecting "a listing of values and types to expose, like (..)" $
207 return (Var.Listing [] True)
210 listingHelp parser [value]
214listingHelp :: Parser a -> [a] -> Parser (Var.Listing a)
215listingHelp parser values =
221 listingHelp parser (value:values)
223 return (Var.Listing (reverse values) False)
227listingValue :: Parser Var.Value
230 [ Var.Value <$> lowVar
236 return (Var.Value op)
240 [ Var.Union name <$> listing capVar
241 , return (Var.Alias name)
250freshLine :: Parser ()
252 do space <- whitespace
253 if space == Freshline
255 else failure (error "TODO freshLine")
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