1.1 --- a/moinformat/parsers/graphviz.py Tue Nov 27 21:12:12 2018 +0100
1.2 +++ b/moinformat/parsers/graphviz.py Tue Nov 27 21:12:40 2018 +0100
1.3 @@ -20,7 +20,8 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from moinformat.parsers.common import ParserBase, get_patterns, group, optional
1.8 +from moinformat.parsers.common import ParserBase, choice, get_patterns, group, \
1.9 + optional
1.10 from moinformat.parsers.moin import MoinParser
1.11 from moinformat.tree.graphviz import Directive
1.12 from moinformat.tree.moin import Text
1.13 @@ -41,8 +42,14 @@
1.14
1.15 "Handle format directives."
1.16
1.17 - key = self.match_group("key")
1.18 - value = self.match_group("value")
1.19 + directive = self.match_group("directive")
1.20 +
1.21 + if directive:
1.22 + key, value = directive.split(None, 1)
1.23 + else:
1.24 + key = self.match_group("key")
1.25 + value = self.match_group("value")
1.26 +
1.27 self.add_node(region, Directive(key, value))
1.28 self.new_block(region)
1.29
1.30 @@ -53,11 +60,17 @@
1.31 syntax = {
1.32 # At start of line:
1.33
1.34 - "directive" : join(("^//", # //
1.35 - group("key", ".*?"), # text-excl-eq-nl
1.36 - optional(join(("=", # eq (optional)
1.37 - group("value", ".*?")))), # text-excl-nl (optional)
1.38 - "\n")), # nl
1.39 + "directive" : choice((join((r"^#", # #
1.40 + group("directive", r".*?$"), # rest of line
1.41 + optional(group("extra", r"\n")))), # nl (optional)
1.42 +
1.43 + # Legacy GraphvizParser directive syntax:
1.44 +
1.45 + join(("^//", # //
1.46 + group("key", ".*?"), # text-excl-eq-nl
1.47 + optional(join(("=", # eq (optional)
1.48 + group("value", ".*?")))), # text-excl-nl (optional)
1.49 + "\n")))), # nl
1.50
1.51 "regionend" : MoinParser.syntax["regionend"],
1.52 }