1.1 --- a/moinformat/parsing.py Thu May 04 22:39:00 2017 +0200
1.2 +++ b/moinformat/parsing.py Fri May 05 00:10:27 2017 +0200
1.3 @@ -20,6 +20,27 @@
1.4 """
1.5
1.6 from moinformat.tree import Block, Region, Text
1.7 +import re
1.8 +
1.9 +# Pattern management.
1.10 +
1.11 +def get_patterns(syntax):
1.12 +
1.13 + "Define patterns for the regular expressions in the 'syntax' mapping."
1.14 +
1.15 + patterns = {}
1.16 + for name, value in syntax.items():
1.17 + patterns[name] = re.compile(value, re.UNICODE | re.MULTILINE)
1.18 + return patterns
1.19 +
1.20 +def combine_patterns(patterns, syntax):
1.21 +
1.22 + "Combine 'patterns' with those defined by the given 'syntax' mapping."
1.23 +
1.24 + p = {}
1.25 + p.update(patterns)
1.26 + p.update(get_patterns(syntax))
1.27 + return p
1.28
1.29 # Tokenising functions.
1.30