1module Parse.Pattern (term, expr) where
3import qualified Data.List as List
4import Text.Parsec ((<|>), (<?>), char, choice, optionMaybe, try)
6import qualified AST.Literal as L
7import qualified AST.Pattern as P
8import qualified AST.Variable as Var
10import qualified Parse.Literal as Literal
11import qualified Reporting.Annotation as A
12import qualified Reporting.Region as R
19 [ char '_' >> return P.Anything
21 , chunksToPatterns <$> dotSep1 capVar
22 , P.Literal <$> Literal.literal
25 chunksToPatterns chunks =
26 case List.intercalate "." chunks of
28 P.Literal (L.Boolean True)
31 P.Literal (L.Boolean False)
34 P.Data (Var.Raw name) []
37asPattern :: IParser P.Raw -> IParser P.Raw
38asPattern patternParser =
39 do pattern <- patternParser
41 let (A.A (R.Region start _) _) = pattern
43 maybeAlias <- optionMaybe asAlias
47 do end <- getMyPosition
48 return (A.at start end (P.Alias alias pattern))
54 do try (whitespace >> reserved "as")
59record :: IParser P.Raw
62 (P.Record <$> brackets (commaSep1 lowVar))
67 do (start, patterns, end) <-
68 located (parens (commaSep expr))
75 return (A.at start end (P.tuple patterns))
81 do (_, patterns, end) <- located (commaSep expr)
82 return (P.list end patterns)
87 choice [ record, tuple, list, basic ]
91patternConstructor :: IParser P.Raw
94 do name <- List.intercalate "." <$> dotSep1 capVar
97 return $ P.Literal (L.Boolean True)
100 return $ P.Literal (L.Boolean False)
103 P.Data (Var.Raw name) <$> spacePrefix term
108 asPattern subPattern <?> "a pattern"
111 do patterns <- consSep1 (patternConstructor <|> term)
113 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