1.1 --- a/moinformat/parsers/moin.py Tue Aug 07 17:05:58 2018 +0200
1.2 +++ b/moinformat/parsers/moin.py Tue Aug 07 17:06:26 2018 +0200
1.3 @@ -35,12 +35,13 @@
1.4
1.5 # Document tree nodes.
1.6
1.7 -from moinformat.tree.moin import Anchor, Break, DefItem, DefTerm, FontStyle, \
1.8 - Heading, Larger, LineBreak, Link, List, \
1.9 - ListItem, Macro, Monospace, Region, Rule, \
1.10 - Smaller, Strikethrough, Subscript, \
1.11 - Superscript, Table, TableAttr, TableAttrs, \
1.12 - TableCell, TableRow, Text, Underline
1.13 +from moinformat.tree.moin import Anchor, Break, Comment, DefItem, DefTerm, \
1.14 + Directive, FontStyle, Heading, Larger, \
1.15 + LineBreak, Link, List, ListItem, Macro, \
1.16 + Monospace, Region, Rule, Smaller, \
1.17 + Strikethrough, Subscript, Superscript, Table, \
1.18 + TableAttr, TableAttrs, TableCell, TableRow, \
1.19 + Text, Underline
1.20
1.21 join = "".join
1.22
1.23 @@ -85,9 +86,10 @@
1.24 self.items = self.get_items(s)
1.25 self.region = Region([], type="moin")
1.26
1.27 - # Parse page header.
1.28 + # Parse page header and directives.
1.29
1.30 self.parse_region_header(self.region)
1.31 + self.parse_region_directives(self.region)
1.32
1.33 # Handle pages directly with this parser. Pages do not need to use an
1.34 # explicit format indicator.
1.35 @@ -170,6 +172,15 @@
1.36 self.add_node(region, Break())
1.37 self.new_block(region)
1.38
1.39 + def parse_comment(self, region):
1.40 +
1.41 + "Handle a comment within 'region'."
1.42 +
1.43 + comment = self.match_group("comment")
1.44 + extra = self.match_group("extra")
1.45 + self.add_node(region, Comment(comment, extra))
1.46 + self.new_block(region)
1.47 +
1.48 def parse_defitem(self, region, extra=""):
1.49
1.50 "Handle a definition item within 'region'."
1.51 @@ -205,6 +216,15 @@
1.52 self.parse_region_details(region, ["deftermsep"])
1.53 self.parse_defitem(region, extra)
1.54
1.55 + def parse_directive(self, region):
1.56 +
1.57 + "Handle a processing directive within 'region'."
1.58 +
1.59 + directive = self.match_group("directive")
1.60 + extra = self.match_group("extra")
1.61 + self.add_node(region, Directive(directive, extra))
1.62 + self.new_block(region)
1.63 +
1.64 def parse_fontstyle(self, region):
1.65
1.66 "Handle emphasis and strong styles."
1.67 @@ -581,12 +601,17 @@
1.68 "regionend" : join((r"\N*", # ws... (optional)
1.69 group("feature", join((
1.70 group("level", repeat("[}]", 3)), # }}}...
1.71 - group("extra", r"\n"),
1.72 - "?"))))), # nl (optional)
1.73 + optional(group("extra", r"\n"))))))), # nl (optional)
1.74 +
1.75 + # Region header and directives:
1.76
1.77 "header" : join(("#!", # #!
1.78 group("args", ".*?"), "\n")), # text-excl-nl
1.79
1.80 + "directive" : join((r"^#", # #
1.81 + group("directive", r".*?$"), # rest of line
1.82 + optional(group("extra", r"\n")))), # nl (optional)
1.83 +
1.84 # Region contents:
1.85
1.86 # Line-oriented patterns support features which require their own
1.87 @@ -594,6 +619,10 @@
1.88
1.89 "break" : r"^(\s*?)\n", # blank line
1.90
1.91 + "comment" : join((r"^##", # ##
1.92 + group("comment", r".*?$"), # rest of line
1.93 + optional(group("extra", r"\n")))), # nl (optional)
1.94 +
1.95 "defterm" : join(("^",
1.96 group("pad", r"\N+"), # ws...
1.97 expect(".+?::"))), # text ::
1.98 @@ -772,7 +801,7 @@
1.99 listitem_pattern_names = inline_pattern_names + ["listitemend"]
1.100
1.101 region_without_table_pattern_names = inline_pattern_names + list_pattern_names + [
1.102 - "break", "heading", "defterm", "defterm_empty",
1.103 + "break", "comment", "heading", "defterm", "defterm_empty",
1.104 "regionend", "rule",
1.105 ]
1.106
1.107 @@ -799,10 +828,12 @@
1.108 "break" : parse_break,
1.109 "colour" : parse_colour,
1.110 "colspan" : parse_colspan,
1.111 + "comment" : parse_comment,
1.112 "defterm" : parse_defterm,
1.113 "defterm_empty" : parse_defterm_empty,
1.114 "deftermend" : end_region,
1.115 "deftermsep" : end_region,
1.116 + "directive" : parse_directive,
1.117 "fontstyle" : parse_fontstyle,
1.118 "halign" : parse_halign,
1.119 "heading" : parse_heading,