2module Parse.Pattern (term, expr) where
4import Control.Applicative ((<$>))
5import Data.Char (isUpper)
6import Data.List (intercalate)
7import Text.Parsec hiding (newline,spaces,State)
11import SourceSyntax.Literal
12import SourceSyntax.Pattern hiding (tuple, list)
13import qualified SourceSyntax.Pattern as Pattern
15basic :: IParser Pattern
17 [ char '_' >> return PAnything
20 "True" -> PLiteral (Boolean True)
21 "False" -> PLiteral (Boolean False)
22 c:_ | isUpper c -> PData v []
24 , PLiteral <$> literal
27asPattern :: Pattern -> IParser Pattern
29 var <- optionMaybe (try (whitespace >> reserved "as" >> whitespace >> lowVar))
31 Just v -> PAlias v pattern
34record :: IParser Pattern
35record = PRecord <$> brackets (commaSep1 lowVar)
37tuple :: IParser Pattern
38tuple = do ps <- parens (commaSep expr)
39 return $ case ps of { [p] -> p; _ -> Pattern.tuple ps }
41list :: IParser Pattern
42list = Pattern.list <$> braces (commaSep expr)
44term :: IParser Pattern
46 (choice [ record, tuple, list, basic ]) <?> "pattern"
48patternConstructor :: IParser Pattern
49patternConstructor = do
50 v <- intercalate "." <$> dotSep1 capVar
52 "True" -> return $ PLiteral (Boolean True)
53 "False" -> return $ PLiteral (Boolean False)
54 _ -> PData v <$> spacePrefix term
56expr :: IParser Pattern
58 patterns <- consSep1 (patternConstructor <|> term)
59 asPattern (foldr1 Pattern.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