2module Parse.Pattern (term, expr) where
4import Control.Applicative ((<$>))
5import Data.Char (isUpper)
6import qualified Data.List as List
7import Text.Parsec hiding (newline,spaces,State)
12import qualified AST.Pattern as P
13import qualified AST.Variable as Var
15basic :: IParser P.RawPattern
17 [ char '_' >> return P.Anything
20 "True" -> P.Literal (Boolean True)
21 "False" -> P.Literal (Boolean False)
22 c:_ | isUpper c -> P.Data (Var.Raw v) []
24 , P.Literal <$> literal
27asPattern :: P.RawPattern -> IParser P.RawPattern
29 var <- optionMaybe (try (whitespace >> reserved "as" >> whitespace >> lowVar))
31 Just v -> P.Alias v pattern
34record :: IParser P.RawPattern
35record = P.Record <$> brackets (commaSep1 lowVar)
37tuple :: IParser P.RawPattern
39 ps <- parens (commaSep expr)
44list :: IParser P.RawPattern
45list = P.list <$> braces (commaSep expr)
47term :: IParser P.RawPattern
49 (choice [ record, tuple, list, basic ]) <?> "pattern"
51patternConstructor :: IParser P.RawPattern
52patternConstructor = do
53 v <- List.intercalate "." <$> dotSep1 capVar
55 "True" -> return $ P.Literal (Boolean True)
56 "False" -> return $ P.Literal (Boolean False)
57 _ -> P.Data (Var.Raw v) <$> spacePrefix term
59expr :: IParser P.RawPattern
61 patterns <- consSep1 (patternConstructor <|> term)
62 asPattern (foldr1 P.cons patterns) <?> "pattern"
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