Module providing pattern matching and capturing on Identifier
s.
A very simple pattern could be, for example, foo/bar
. This pattern will
only match the exact foo/bar
identifier.
To match more than one identifier, there are different captures that one can use:
-
*
: matches exactly one element of an identifier; -
**
: matches one or more elements of an identifier.
Some examples:
-
foo/*
will matchfoo/bar
andfoo/foo
, but notfoo/bar/qux
norfoo
; -
**
will match any non-empty identifier; -
foo/**
will matchfoo/bar
andfoo/bar/qux
, but notbar/foo
norfoo
;
A small warning: patterns are not globs. Using foo/*.markdown
will not do
what you probably intended, as it will only match the file which is literally
called foo/*.markdown
. Remember that these captures only work on elements
of identifiers as a whole; not on parts of these elements.
Furthermore, the match
function allows the user to get access to the
elements captured by the capture elements in the pattern.
- data Pattern
- parsePattern :: String -> Pattern
- match :: Pattern -> Identifier -> Maybe [Identifier]
- doesMatch :: Pattern -> Identifier -> Bool
- matches :: Pattern -> [Identifier] -> [Identifier]
- fromCapture :: Pattern -> Identifier -> Identifier
- fromCaptureString :: Pattern -> String -> Identifier
- fromCaptures :: Pattern -> [Identifier] -> Identifier
Documentation
Type that allows matching on identifiers
parsePattern :: String -> PatternSource
Parse a pattern from a string
match :: Pattern -> Identifier -> Maybe [Identifier]Source
Match an identifier against a pattern, generating a list of captures
doesMatch :: Pattern -> Identifier -> BoolSource
Check if an identifier matches a pattern
matches :: Pattern -> [Identifier] -> [Identifier]Source
Given a list of identifiers, retain only those who match the given pattern
fromCapture :: Pattern -> Identifier -> IdentifierSource
Create an identifier from a pattern by filling in the captures with a given string
Example:
fromCapture (parsePattern "tags/*") (parseIdentifier "foo")
Result:
"tags/foo"
fromCaptureString :: Pattern -> String -> IdentifierSource
Simplified version of fromCapture
which takes a String
instead of an
Identifier
fromCaptureString (parsePattern "tags/*") "foo"
Result:
"tags/foo"
fromCaptures :: Pattern -> [Identifier] -> IdentifierSource
Create an identifier from a pattern by filling in the captures with the given list of strings