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.Region as R
18header :: Parser (Module.Header [Module.UserImport])
23 , Module.defaultHeader <$> chompImports []
31fullHeader :: Parser (Module.Header [Module.UserImport])
35 name <- qualifiedCapVar -- TODO <?> "the name of this module"
37 settings <- effectSettings
38 keyword "exposing" -- TODO <?> "something like `exposing (..)` which replaced `where` in 0.17"
40 exports <- listing (addLocation listingValue)
42 docs <- maybeDocComment
43 imports <- chompImports []
44 return (Module.Header tag name exports settings docs imports)
48-- MODULE TAGS - module, effect module, port module
51sourceTag :: Parser Module.SourceTag
58 do start <- getPosition
63 return (Module.Port (R.Region start end))
65 do start <- getPosition
70 return (Module.Effect (R.Region start end))
75-- EFFECTS - where { command = MyCmd }
78effectSettings :: Parser Module.SourceSettings
88 effectSettingsHelp start [entry]
89 , return Module.emptySettings
93effectSettingsHelp :: R.Position -> [(A.Located Text, A.Located Text)] -> Parser Module.SourceSettings
94effectSettingsHelp start entries =
100 effectSettingsHelp start (entry:entries)
104 return (A.at start end entries)
108setting :: Parser (A.Located Text, A.Located Text)
110 do name <- addLocation lowVar
114 tipe <- addLocation capVar
122maybeDocComment :: Parser (Maybe (A.Located Text))
125 [ do doc <- addLocation docComment
136chompImports :: [Module.UserImport] -> Parser [Module.UserImport]
137chompImports imports =
139 [ do start <- getPosition
142 name <- qualifiedCapVar
146 [ do checkFreshline pos
147 let userImport = method start end name Nothing Var.closedListing
148 chompImports (userImport:imports)
151 [ chompAs start name imports
152 , chompExposing start name Nothing imports
155 , return (reverse imports)
159chompAs :: R.Position -> Text -> [Module.UserImport] -> Parser [Module.UserImport]
160chompAs start name imports =
167 [ do checkFreshline pos
168 let userImport = method start end name (Just alias) Var.closedListing
169 chompImports (userImport:imports)
171 chompExposing start name (Just alias) imports
175chompExposing :: R.Position -> Text -> Maybe Text -> [Module.UserImport] -> Parser [Module.UserImport]
176chompExposing start name maybeAlias imports =
177 do keyword "exposing"
179 exposed <- listing listingValue
182 let userImport = method start end name maybeAlias exposed
183 chompImports (userImport:imports)
186method :: R.Position -> R.Position -> Text -> Maybe Text -> Var.Listing Var.Value -> Module.UserImport
187method start end name maybeAlias exposed =
188 A.at start end ( name, Module.ImportMethod maybeAlias exposed )
195listing :: Parser a -> Parser (Var.Listing a)
197 expecting "a listing of values and types to expose, like (..)" $
205 return (Var.Listing [] True)
208 listingHelp parser [value]
212listingHelp :: Parser a -> [a] -> Parser (Var.Listing a)
213listingHelp parser values =
219 listingHelp parser (value:values)
221 return (Var.Listing (reverse values) False)
225listingValue :: Parser Var.Value
228 [ Var.Value <$> lowVar
234 return (Var.Value op)
238 [ Var.Union name <$> listing capVar
239 , return (Var.Alias name)
248freshLine :: Parser ()
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