Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- match :: String -> Template -> [[(String, Value)]]
- finalize :: [(Name, Match)] -> [(String, Value)]
- keepConsistent :: [(Name, Match)] -> Maybe [(Name, Match)]
- combine :: Match -> [Match] -> Maybe Match
- template :: Template -> ReadP [(Name, Match)]
- token :: Token -> ReadP [(Name, Match)]
- expression :: Expression -> ReadP [(Name, Match)]
- variables :: Operator -> NonEmpty Variable -> ReadP [(Name, Match)]
- vars :: NonEmpty Variable -> Maybe Char -> Char -> (Variable -> ReadP [(Name, Match)]) -> ReadP [(Name, Match)]
- isUndefined :: (Name, Match) -> Bool
- vars' :: Char -> (Variable -> ReadP [(Name, Match)]) -> [Variable] -> ReadP [(Name, Match)]
- undef :: Variable -> (Name, Match)
- char_ :: Char -> ReadP ()
- varEq :: Variable -> ReadP [(Name, Match)]
- name :: Name -> ReadP ()
- variable :: (Char -> Bool) -> Variable -> ReadP [(Name, Match)]
- manyCharacters :: (Char -> Bool) -> ReadP Text
- someEncodedCharacters :: ReadP Text
- some :: ReadP a -> ReadP (NonEmpty a)
- someUnencodedCharacters :: (Char -> Bool) -> ReadP Text
- anEncodedCharacter :: ReadP (Digit, Digit)
- aDigit :: ReadP Digit
- literal :: Literal -> ReadP ()
- literalCharacter :: Character Literal -> ReadP ()
- character :: (Char -> Bool) -> Character tag -> ReadP ()
- encodedCharacter :: Digit -> Digit -> ReadP ()
- digit :: Digit -> ReadP ()
- unencodedCharacter :: (Char -> Bool) -> Char -> ReadP ()
Documentation
match :: String -> Template -> [[(String, Value)]] Source #
Matches a string against a template. This is essentially the opposite of
expand
.
Since there isn't always one unique match, this function returns all the possibilities. It's up to you to select the one that makes the most sense, or to simply grab the first one if you don't care.
>>>
match "" <$> parse "no-match"
Just []>>>
match "no-variables" <$> parse "no-variables"
Just [[]]>>>
match "1-match" <$> parse "{one}-match"
Just [[("one",String "1")]]
Be warned that the number of possible matches can grow quickly if your template has variables next to each other without any separators.
>>>
let Just template = parse "{a}{b}"
>>>
mapM_ print $ match "ab" template
[("a",String "a"),("b",String "b")] [("a",String "ab"),("b",String "")] [("a",String "ab")] [("a",String ""),("b",String "ab")] [("b",String "ab")]
Matching supports everything except explode modifiers ({a*}
), list
values, and dictionary values.
expression :: Expression -> ReadP [(Name, Match)] Source #
vars :: NonEmpty Variable -> Maybe Char -> Char -> (Variable -> ReadP [(Name, Match)]) -> ReadP [(Name, Match)] Source #