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)
11import SourceSyntax.Literal
12import qualified SourceSyntax.Pattern as P
14basic :: IParser P.Pattern
16 [ char '_' >> return P.Anything
19 "True" -> P.Literal (Boolean True)
20 "False" -> P.Literal (Boolean False)
21 c:_ | isUpper c -> P.Data v []
23 , P.Literal <$> literal
26asPattern :: P.Pattern -> IParser P.Pattern
28 var <- optionMaybe (try (whitespace >> reserved "as" >> whitespace >> lowVar))
30 Just v -> P.Alias v pattern
33record :: IParser P.Pattern
34record = P.Record <$> brackets (commaSep1 lowVar)
36tuple :: IParser P.Pattern
38 ps <- parens (commaSep expr)
43list :: IParser P.Pattern
44list = P.list <$> braces (commaSep expr)
46term :: IParser P.Pattern
48 (choice [ record, tuple, list, basic ]) <?> "pattern"
50patternConstructor :: IParser P.Pattern
51patternConstructor = do
52 v <- List.intercalate "." <$> dotSep1 capVar
54 "True" -> return $ P.Literal (Boolean True)
55 "False" -> return $ P.Literal (Boolean False)
56 _ -> P.Data v <$> spacePrefix term
58expr :: IParser P.Pattern
60 patterns <- consSep1 (patternConstructor <|> term)
61 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