Total Complexity | 4 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Coverage | 78.95% |
Changes | 0 |
1 | """Regex primitives.""" |
||
2 | |||
3 | 1 | import re |
|
4 | |||
5 | |||
6 | 1 | ANYTHING = r".+" |
|
7 | 1 | WHITESPACE = r"\s" |
|
8 | 1 | WHITESPACES = r"{0}+".format(WHITESPACE) |
|
9 | 1 | NON_WHITESPACE = r"\S" |
|
10 | 1 | NON_WHITESPACES = r"{0}+".format(NON_WHITESPACE) |
|
11 | 1 | DIGIT = r"\d" |
|
12 | 1 | NUMBER = r"{0}+".format(DIGIT) |
|
13 | 1 | FLOAT = r"{0}.{0}".format(NUMBER) |
|
14 | 1 | START_OF_STRING = r"^" |
|
15 | 1 | END_OF_STRING = r"$" |
|
16 | |||
17 | |||
18 | 1 | def make_matcher(pattern): |
|
19 | return re.compile(pattern, re.VERBOSE).match |
||
20 | |||
21 | |||
22 | 1 | def group(expression): |
|
23 | return "({0})".format(expression) |
||
24 | |||
25 | |||
26 | 1 | def named_group(group_name, expression): |
|
27 | return "(?P<{0}>{1})".format(group_name, expression) |
||
28 | |||
29 | |||
30 | 1 | def choices(values, delimiter="|"): |
|
31 | return delimiter.join(values) |
||
32 |