1module Parse.Pattern (term, expr) where
3import Data.Char (isUpper)
4import qualified Data.List as List
5import Text.Parsec ((<|>), (<?>), char, choice, optionMaybe, try)
7import qualified AST.Literal as L
8import qualified AST.Pattern as P
9import qualified AST.Variable as Var
11import qualified Parse.Literal as Literal
12import qualified Reporting.Annotation as A
13import qualified Reporting.Region as R
20 [ char '_' >> return P.Anything
21 , stringToPattern <$> var
22 , P.Literal <$> Literal.literal
28 P.Literal (L.Boolean True)
31 P.Literal (L.Boolean False)
34 P.Data (Var.Raw str) []
40asPattern :: IParser P.Raw -> IParser P.Raw
41asPattern patternParser =
42 do pattern <- patternParser
44 let (A.A (R.Region start _) _) = pattern
46 maybeAlias <- optionMaybe asAlias
50 do end <- getMyPosition
51 return (A.at start end (P.Alias alias pattern))
57 do try (whitespace >> reserved "as")
62record :: IParser P.Raw
65 (P.Record <$> brackets (commaSep1 lowVar))
70 do (start, patterns, end) <-
71 located (parens (commaSep expr))
78 return (A.at start end (P.tuple patterns))
84 do (_, patterns, end) <- located (commaSep expr)
85 return (P.list end patterns)
90 choice [ record, tuple, list, basic ]
94patternConstructor :: IParser P.Raw
97 do v <- List.intercalate "." <$> dotSep1 capVar
99 "True" -> return $ P.Literal (L.Boolean True)
100 "False" -> return $ P.Literal (L.Boolean False)
101 _ -> P.Data (Var.Raw v) <$> spacePrefix term
106 asPattern subPattern <?> "a pattern"
109 do patterns <- consSep1 (patternConstructor <|> term)
111 return (P.consMany end patterns)
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