1 #!/usr/bin/env python 2 3 """ 4 Moin wiki format parser. 5 6 Copyright (C) 2017, 2018 Paul Boddie <paul@boddie.org.uk> 7 8 This program is free software; you can redistribute it and/or modify it under 9 the terms of the GNU General Public License as published by the Free Software 10 Foundation; either version 3 of the License, or (at your option) any later 11 version. 12 13 This program is distributed in the hope that it will be useful, but WITHOUT 14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 15 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 16 details. 17 18 You should have received a copy of the GNU General Public License along with 19 this program. If not, see <http://www.gnu.org/licenses/>. 20 """ 21 22 # Document transformations. 23 24 from moinformat.macros import get_macro 25 26 # Parser functionality and pattern definition. 27 28 from moinformat.parsers.common import ParserBase, get_patterns, choice, \ 29 excl, expect, group, optional, recur, \ 30 repeat 31 32 # Serialisation. 33 34 from moinformat.serialisers import serialise 35 36 # Document tree nodes. 37 38 from moinformat.tree.moin import Anchor, Break, Comment, DefItem, DefTerm, \ 39 Directive, FontStyle, Heading, Larger, \ 40 LineBreak, Link, LinkLabel, LinkParameter, \ 41 List, ListItem, Macro, Monospace, Region, \ 42 Rule, Smaller, Strikethrough, Subscript, \ 43 Superscript, Table, TableAttr, TableAttrs, \ 44 TableCell, TableRow, Text, Transclusion, \ 45 Underline 46 47 join = "".join 48 49 class MoinParser(ParserBase): 50 51 "A wiki region parser." 52 53 format = "moin" 54 55 def __init__(self, metadata, parsers=None, root=None): 56 57 """ 58 Initialise the parser with the given 'metadata' and optional 'parsers'. 59 An optional 'root' indicates the document-level parser. 60 """ 61 62 ParserBase.__init__(self, metadata, parsers, root) 63 64 # Record certain node occurrences for later evaluation. 65 66 self.macros = [] 67 68 # Record headings for identifier disambiguation. 69 70 self.headings = [] 71 72 # Principal parser methods. 73 74 def parse(self, s): 75 76 """ 77 Parse page text 's'. Pages consist of regions delimited by markers. 78 """ 79 80 self.items = self.get_items(s) 81 self.region = Region([], type="moin") 82 83 # Parse page header and directives. 84 85 self.parse_region_header(self.region) 86 self.parse_region_directives(self.region) 87 88 # Handle pages directly with this parser. Pages do not need to use an 89 # explicit format indicator. 90 91 if not self.region.type: 92 self.parse_region_content(self.items, self.region) 93 94 # Otherwise, test the type and find an appropriate parser. 95 96 else: 97 self.parse_region_type(self.region) 98 99 # Assign heading identifiers. 100 101 self.identify_headings() 102 103 return self.region 104 105 106 107 # Macro evaluation. 108 109 def evaluate_macros(self): 110 111 "Evaluate the macro nodes in the document." 112 113 for node in self.macros: 114 115 # Obtain a class for the named macro. 116 117 macro_cls = get_macro(node.name) 118 if not macro_cls: 119 continue 120 121 # Instantiate the class and evaluate the macro. 122 123 macro = macro_cls(node, self.region) 124 macro.evaluate() 125 126 # Heading disambiguation. 127 128 def identify_headings(self): 129 130 "Assign identifiers to headings based on their textual content." 131 132 d = {} 133 134 for heading in self.headings: 135 text = heading.text_content() 136 137 if not d.has_key(text): 138 d[text] = 0 139 heading.identifier = text 140 else: 141 d[text] += 1 142 heading.identifier = "%s-%d" % (text, d[text]) 143 144 145 146 # Conversion back to text. 147 148 def get_serialiser(self): 149 150 "Return metadata employing Moin as the output format." 151 152 metadata = self.metadata.copy() 153 metadata.set("link_format", None) 154 metadata.set("output_context", "standalone") 155 metadata.set("output_format", "moin") 156 return metadata.get_serialiser() 157 158 159 160 # Parser methods supporting different page features. 161 162 def parse_attrname(self, attrs): 163 164 "Handle an attribute name within 'attrs'." 165 166 name = self.match_group("name") 167 attr = TableAttr(name) 168 169 preceding = self.read_until(["attrvalue"], False) 170 if preceding == "": 171 attr.quote = self.match_group("quote") 172 attr.value = self.match_group("value") 173 174 attrs.append(attr) 175 176 def parse_break(self, region): 177 178 "Handle a paragraph break within 'region'." 179 180 self.add_node(region, Break()) 181 self.new_block(region) 182 183 def parse_comment(self, region): 184 185 "Handle a comment within 'region'." 186 187 comment = self.match_group("comment") 188 extra = self.match_group("extra") 189 self.add_node(region, Comment(comment, extra)) 190 self.new_block(region) 191 192 def parse_defitem(self, region, extra=""): 193 194 "Handle a definition item within 'region'." 195 196 pad = self.match_group("pad") 197 item = DefItem([], pad, extra) 198 self.parse_region_details(item, self.listitem_pattern_names) 199 self.add_node(region, item) 200 self.new_block(region) 201 202 def parse_defterm(self, region): 203 204 "Handle a definition term within 'region'." 205 206 pad = self.match_group("pad") 207 term = DefTerm([], pad) 208 self.parse_region_details(term, ["deftermend", "deftermsep"]) 209 self.add_node(region, term) 210 211 if self.matching_pattern() == "deftermsep": 212 self.parse_defitem(region) 213 214 # Add padding from the separator to the term, there being no item. 215 216 else: 217 term.extra = self.match_group("pad") 218 219 def parse_defterm_empty(self, region): 220 221 "Handle an empty definition term within 'region'." 222 223 extra = self.match_group("pad") 224 self.parse_region_details(region, ["deftermsep"]) 225 self.parse_defitem(region, extra) 226 227 def parse_directive(self, region): 228 229 "Handle a processing directive within 'region'." 230 231 directive = self.match_group("directive") 232 extra = self.match_group("extra") 233 self.add_node(region, Directive(directive, extra)) 234 self.new_block(region) 235 236 def parse_fontstyle(self, region): 237 238 "Handle emphasis and strong styles." 239 240 n = len(self.match_group("style")) 241 242 # Handle endings. 243 244 if isinstance(region, FontStyle): 245 emphasis = n in (2, 4, 5) 246 strong = n in (3, 5, 6) 247 active = True 248 249 if region.emphasis and emphasis: 250 active = region.close_emphasis() 251 n -= 2 252 if region.strong and strong: 253 active = region.close_strong() 254 n -= 3 255 256 if not active: 257 if n: 258 self.items.rewind(n) 259 raise StopIteration 260 261 elif not n: 262 return 263 264 # Handle new styles. 265 266 emphasis = n in (2, 4, 5) 267 strong = n in (3, 5, 6) 268 double = n in (4, 6) 269 270 span = FontStyle([], emphasis, strong) 271 if not double: 272 self.parse_region_details(span, self.inline_pattern_names) 273 region.append_inline(span) 274 275 def parse_halign(self, attrs): 276 277 "Handle horizontal alignment within 'attrs'." 278 279 value = self.match_group("value") 280 attr = TableAttr("halign", value == "(" and "left" or value == ")" and "right" or "center", True) 281 attrs.append(attr) 282 283 def parse_heading(self, region): 284 285 "Handle a heading." 286 287 start_extra = self.match_group("extra") 288 level = len(self.match_group("level")) 289 start_pad = self.match_group("pad") 290 heading = Heading([], level, start_extra, start_pad) 291 self.parse_region_details(heading, ["headingend"] + self.inline_pattern_names) 292 self.add_node(region, heading) 293 self.new_block(region) 294 295 # Record the heading for later processing. 296 297 self.root.headings.append(heading) 298 299 def parse_heading_end(self, heading): 300 301 "Handle the end of a heading." 302 303 level = len(self.match_group("level")) 304 if heading.level == level: 305 heading.end_pad = self.match_group("pad") 306 heading.end_extra = self.match_group("extra") 307 raise StopIteration 308 309 def parse_list(self, item): 310 311 "Create a list, starting with 'item'." 312 313 list = List([item], item.indent, item.marker, item.num) 314 self.parse_region_details(list, self.list_pattern_names, True) 315 return list 316 317 def parse_listitem(self, region): 318 319 "Handle a list item marker within 'region'." 320 321 indent = len(self.match_group("indent")) 322 marker = self.match_group("marker") 323 num = self.match_group("num") 324 space = self.match_group("pad") 325 326 last = region.node(-1) 327 328 new_list = not isinstance(last, (List, ListItem)) 329 same_indent = not new_list and indent == last.indent 330 new_marker = not new_list and last.marker != marker and same_indent 331 new_num = not new_list and num is not None and last.num != num and same_indent 332 333 # If the marker or number changes at the same indent, or if the indent 334 # is smaller, queue the item and end the list. 335 336 # Note that Moin format does not seek to support item renumbering, 337 # instead starting new lists on number changes. 338 339 if not new_list and (new_marker or new_num or indent < last.indent): 340 self.queue_match() 341 self.end_region(region) 342 343 # Obtain a list item and populate it. 344 345 item = ListItem([], indent, marker, space, num) 346 self.parse_region_details(item, self.listitem_pattern_names) 347 348 # Start a new list if not preceded by a list item, adding a trailing 349 # block for new elements. 350 351 if new_list: 352 item = self.parse_list(item) 353 self.add_node(region, item) 354 self.new_block(region) 355 356 # Add a nested list to the last item. 357 358 elif indent > last.indent: 359 item = self.parse_list(item) 360 self.add_node(last, item) 361 362 # Add the item to the current list. 363 364 else: 365 self.add_node(region, item) 366 367 def parse_rule(self, region): 368 369 "Handle a horizontal rule within 'region'." 370 371 length = len(self.match_group("rule")) 372 rule = Rule(length) 373 self.add_node(region, rule) 374 self.new_block(region) 375 376 def parse_section(self, region): 377 378 "Handle the start of a new section within 'region'." 379 380 # Parse the section and start a new block after the section. 381 382 indent = len(self.match_group("indent")) 383 level = len(self.match_group("level")) 384 385 section = self.parse_region(level, indent, "inline") 386 387 # If the section is inline, treat it like any other inline element. 388 389 if section.type == "inline": 390 region.append_inline(section) 391 392 # Otherwise, add it as a new block element. 393 394 else: 395 self.add_node(region, section) 396 if region.allow_blocks: 397 self.new_block(region) 398 399 def parse_table_attrs(self, cell): 400 401 "Handle the start of table attributes within 'cell'." 402 403 attrs = TableAttrs([]) 404 self.parse_region_details(attrs, self.table_attr_pattern_names) 405 406 # Test the validity of the attributes. 407 408 last = None 409 410 for node in attrs.nodes: 411 412 # Text separator nodes must be whitespace. 413 414 if isinstance(node, Text): 415 if node.s.strip(): 416 break 417 418 # Named attributes must be preceded by space if not the first. 419 420 elif last and not node.concise and not isinstance(last, Text): 421 break 422 423 last = node 424 425 # All nodes were valid: preserve the collection. 426 427 else: 428 # Add the attributes as a node, also recording their presence. 429 430 cell.append(attrs) 431 cell.attrs = attrs 432 return 433 434 # Invalid nodes were found: serialise the attributes as text. 435 436 cell.append_inline(Text(serialise(attrs, self.get_serialiser()))) 437 438 def parse_table_row(self, region): 439 440 "Handle the start of a table row within 'region'." 441 442 # Identify any active table. 443 444 table = region.node(-2) 445 block = region.node(-1) 446 447 if not (isinstance(table, Table) and block.empty()): 448 new_table = table = Table([]) 449 else: 450 new_table = None 451 452 row = TableRow([]) 453 454 while True: 455 cell = TableCell([]) 456 self.parse_region_details(cell, self.table_row_pattern_names) 457 458 # Handle the end of the row. 459 460 if self.matching_pattern() == "tableend": 461 trailing = self.match_group("extra") 462 463 # If the cell was started but not finished, convert the row into text. 464 465 if not row.nodes or not cell.empty(): 466 467 # Convert the nodes back to text. 468 469 serialiser = self.get_serialiser() 470 471 for node in row.nodes: 472 region.append_inline(Text(serialise(node, serialiser))) 473 474 region.append_inline(Text(serialise(cell, serialiser) + trailing)) 475 476 self.new_block(region) 477 return 478 479 # Append the final cell, if not empty. 480 481 else: 482 row.trailing = trailing 483 484 if not cell.empty(): 485 row.append(cell) 486 break 487 488 # A cell separator has been found. 489 490 row.append(cell) 491 492 # Add the row to the table and any new table to the region. 493 494 table.add(row) 495 if new_table: 496 self.add_node(region, new_table) 497 498 self.new_block(region) 499 500 def parse_valign(self, attrs): 501 502 "Handle vertical alignment within 'attrs'." 503 504 value = self.match_group("value") 505 attr = TableAttr("valign", value == "^" and "top" or "bottom", True) 506 attrs.append(attr) 507 508 509 510 def inline_patterns_for(self, name): 511 names = self.inline_pattern_names[:] 512 names[names.index(name)] = "%send" % name 513 return names 514 515 516 517 # Inline formatting handlers. 518 519 def parse_inline(self, region, cls, pattern_name): 520 521 "Handle an inline region." 522 523 span = cls([]) 524 self.parse_region_details(span, self.inline_patterns_for(pattern_name)) 525 region.append_inline(span) 526 527 def parse_larger(self, region): 528 self.parse_inline(region, Larger, "larger") 529 530 def parse_monospace(self, region): 531 span = Monospace([]) 532 self.parse_region_details(span, ["monospaceend"]) 533 region.append_inline(span) 534 535 def parse_smaller(self, region): 536 self.parse_inline(region, Smaller, "smaller") 537 538 def parse_strike(self, region): 539 self.parse_inline(region, Strikethrough, "strike") 540 541 def parse_sub(self, region): 542 self.parse_inline(region, Subscript, "sub") 543 544 def parse_super(self, region): 545 self.parse_inline(region, Superscript, "super") 546 547 def parse_underline(self, region): 548 self.parse_inline(region, Underline, "underline") 549 550 # Link formatting handlers. 551 552 def _parse_link(self, region, cls, pattern_names): 553 target = self.match_group("target") 554 end = self.match_group("end") 555 556 span = cls([], target) 557 558 # Obtain the extra details. 559 560 if not end: 561 cls = LinkLabel 562 563 # Introduce a label or parameter for each separated region. 564 565 while True: 566 param = cls([]) 567 self.parse_region_details(param, pattern_names) 568 span.append(param) 569 570 if self.matching_pattern() != "linksep": 571 break 572 573 cls = LinkParameter 574 575 region.append_inline(span) 576 577 def parse_link(self, region): 578 self._parse_link(region, Link, self.link_pattern_names) 579 580 def parse_transclusion(self, region): 581 self._parse_link(region, Transclusion, self.transclusion_pattern_names) 582 583 584 585 # Complete inline pattern handlers. 586 587 def parse_anchor(self, region): 588 target = self.match_group("target") 589 anchor = Anchor(target) 590 region.append_inline(anchor) 591 592 def parse_linebreak(self, region): 593 region.append_inline(LineBreak()) 594 595 def parse_macro(self, region): 596 name = self.match_group("name") 597 args = self.match_group("args") 598 599 # Obtain the raw arguments. Moin usually leaves it to the macro to 600 # interpret the individual arguments. 601 602 arglist = args and args.split(",") or [] 603 macro = Macro(name, arglist, region.append_point(), region) 604 region.append_inline(macro) 605 606 # Record the macro for later processing. 607 608 self.root.macros.append(macro) 609 610 611 612 # Table attribute handlers. 613 614 def parse_table_attr(self, attrs, pattern_name): 615 616 "Handle a table attribute." 617 618 attrs.append(TableAttr(pattern_name, self.match_group("value"), True)) 619 620 def parse_colour(self, cell): 621 self.parse_table_attr(cell, "colour") 622 623 def parse_colspan(self, cell): 624 self.parse_table_attr(cell, "colspan") 625 626 def parse_rowspan(self, cell): 627 self.parse_table_attr(cell, "rowspan") 628 629 def parse_width(self, cell): 630 self.parse_table_attr(cell, "width") 631 632 633 634 # Regular expressions. 635 636 syntax = { 637 # Page regions: 638 639 "regionstart" : join((group("indent", r"\N*"), # ws... (optional) 640 group("level", repeat("[{]", 3)))), # {{{... 641 642 "regionend" : join((r"\N*", # ws... (optional) 643 group("feature", join(( 644 group("level", repeat("[}]", 3)), # }}}... 645 optional(group("extra", r"\n"))))))), # nl (optional) 646 647 # Region header and directives: 648 649 "header" : join(("#!", # #! 650 group("args", ".*?"), "\n")), # text-excl-nl 651 652 "directive" : join((r"^#", # # 653 group("directive", r".*?$"), # rest of line 654 optional(group("extra", r"\n")))), # nl (optional) 655 656 # Region contents: 657 658 # Line-oriented patterns support features which require their own 659 # separate lines. 660 661 "break" : r"^(\s*?)\n", # blank line 662 663 "comment" : join((r"^##", # ## 664 group("comment", r".*?$"), # rest of line 665 optional(group("extra", r"\n")))), # nl (optional) 666 667 "defterm" : join(("^", 668 group("pad", r"\N+"), # ws... 669 expect(".+?::"))), # text :: 670 671 "defterm_empty" : join(("^", 672 group("pad", r"\N+"), # ws... 673 expect("::\s+"))), # :: ws... 674 675 "heading" : join(("^", 676 group("extra", r"\N*"), # ws... (optional) 677 group("level", "=+"), # =... 678 group("pad", r"\s+"), # ws... 679 expect(join((r".*?\N+", # text 680 recur("level"), # =... 681 r"\N*$"))))), # ws... (optional) 682 683 "listitem" : join(("^", 684 group("indent", r"\N+"), # ws... 685 group("marker", r"\*"), # list-marker 686 group("pad", r"\s*"))), # ws... (optional) 687 688 "listitem_num" : join(("^", 689 group("indent", r"\N+"), # ws... 690 group("marker", r"\d+\."), # decimal-marker 691 optional(join(("#", group("num", r"\d+")))), # # num (optional) 692 group("pad", r"\s+"))), # ws... 693 694 "listitem_alpha": join(("^", 695 group("indent", r"\N+"), # ws... 696 group("marker", r"[aA]\."), # alpha-marker 697 optional(join(("#", group("num", r"\d+")))), # # num (optional) 698 group("pad", r"\s+"))), # ws... 699 700 "listitem_roman": join(("^", 701 group("indent", r"\N+"), # ws... 702 group("marker", r"[iI]\."), # roman-marker 703 optional(join(("#", group("num", r"\d+")))), # # num (optional) 704 group("pad", r"\s+"))), # ws... 705 706 "listitem_dot" : join(("^", 707 group("indent", r"\N+"), # ws... 708 group("marker", r"\."), # dot-marker 709 group("pad", r"\s*"))), # ws... (optional) 710 711 "tablerow" : r"^\|\|", # || 712 713 # Region contents: 714 715 # Inline patterns are for markup features that appear within blocks. 716 # The patterns below start inline spans that can contain other markup 717 # features. 718 719 "fontstyle" : group("style", repeat("'", 2, 6)), # ''... 720 "larger" : r"~\+", # ~+ 721 "monospace" : r"`", # ` 722 "rule" : group("rule", "-----*"), # ----... 723 "smaller" : r"~-", # ~- 724 "strike" : r"--\(", # --( 725 "sub" : r",,", # ,, 726 "super" : r"\^", # ^ 727 "underline" : r"__", # __ 728 729 # Links and transclusions may start inline spans. 730 731 "link" : join((r"\[\[", # [[ 732 group("target", ".*?"), # ... 733 choice((r"\|", # | 734 group("end", r"]]"))))), # ]] 735 736 "transclusion" : join((r"\{\{", # {{ 737 excl(r"\{"), # not-{ 738 group("target", ".*?"), # ... 739 choice((r"\|", # | 740 group("end", r"}}"))))), # }} 741 742 # Complete inline patterns are for markup features that do not support 743 # arbitrary content within them: 744 745 "anchor" : join((r"\(\(", # (( 746 group("target", ".*?"), # target 747 r"\)\)")), # )) 748 749 "linebreak" : r"\\\\", # \\ 750 751 "macro" : join(("<<", # << 752 group("name", "\w+?"), # digit-letter... 753 optional(join((r"\(", # ( (optional) 754 group("args", ".*?"), # not-)... 755 r"\)"))), # ) (optional) 756 ">>")), # >> 757 758 # Ending patterns for inline features: 759 760 "largerend" : r"\+~", # +~ 761 "linkend" : r"]]", # ]] 762 "monospaceend" : r"`", # ` 763 "smallerend" : r"-~", # -~ 764 "strikeend" : r"\)--", # )-- 765 "subend" : r",,", # ,, 766 "superend" : r"\^", # ^ 767 "transclusionend": r"}}", # }} 768 "underlineend" : r"__", # __ 769 770 # Heading contents: 771 772 "headingend" : join((group("pad", r"\N+"), # ws... 773 group("level", "=+"), # =... 774 group("extra", r"\N*\n"))), # ws (optional) nl 775 776 # Link/transclusion contents: 777 778 "linksep" : r"\|", # | 779 780 # List contents: 781 782 "deftermend" : join(("::", group("pad", r"\s*?\n"))), # :: 783 # ws... (optional) 784 # nl 785 786 "deftermsep" : join(("::", group("pad", r"\s+"))), # :: 787 # ws... 788 789 "listitemend" : join((r"^", # next line 790 choice((expect(r"[^\s]"), # without indent 791 expect(r"\Z"), # end of string 792 expect(r"\N+\*"), # or with ws... list-marker 793 expect(r"\N+\d\."), # or with ws... decimal-marker 794 expect(r"\N+[aA]\."), # or with ws... alpha-marker 795 expect(r"\N+[iI]\."), # or with ws... roman-marker 796 expect(r"\N+\."), # or with ws... dot-marker 797 expect(r"\N+.+?::\s"), # or with ws... text :: ws (next defterm) 798 expect(r"\N+::\s"))))), # or with ws... :: ws (next defitem) 799 800 # Table contents: 801 802 "tableattrs" : join(("<", # lt 803 excl("<"))), # not-lt 804 805 "tablecell" : r"\|\|", # || 806 807 "tableend" : join((group("extra", r"\s*?"), # ws... (optional) 808 "^")), # next line 809 810 # Table attributes: 811 812 "tableattrsend" : r">", # > 813 "halign" : group("value", "[(:)]"), # halign-marker 814 "valign" : group("value", "[v^]"), # valign-marker 815 "colour" : group("value", join(("\#", # # 816 repeat("[0-9A-F]", 6, 6)))), # nnnnnn 817 818 "colspan" : join(("-", # - 819 group("value", "\d+"))), # n... 820 821 "rowspan" : join((r"\|", # | 822 group("value", "\d+"))), # n... 823 824 "width" : group("value", "\d+%"), # n... % 825 826 "attrname" : join((excl(r"[-\d]"), # not-dash-or-digit 827 group("name", r"[-\w]+"))), # dash-digit-letter... 828 829 "attrvalue" : join(("=", group("quote", r"\Q"), # quote 830 group("value", ".*?"), # non-quote... (optional) 831 recur("quote"))), # quote 832 } 833 834 patterns = get_patterns(syntax) 835 836 837 838 # Patterns available within certain markup features. 839 840 table_attr_pattern_names = [ 841 "attrname", "colour", "colspan", "halign", "rowspan", "tableattrsend", 842 "valign", "width" 843 ] 844 845 inline_without_links_pattern_names = [ 846 "anchor", "fontstyle", "larger", "linebreak", "macro", 847 "monospace", "regionstart", "smaller", "strike", "sub", "super", 848 "underline", 849 ] 850 851 inline_pattern_names = inline_without_links_pattern_names + [ 852 "link", "transclusion"] 853 854 link_pattern_names = inline_without_links_pattern_names + [ 855 "linkend", "linksep", "transclusion"] 856 857 list_pattern_names = [ 858 "listitem", "listitem_alpha", "listitem_dot", "listitem_num", 859 "listitem_roman", 860 ] 861 862 listitem_pattern_names = inline_pattern_names + ["listitemend"] 863 864 region_without_table_pattern_names = inline_pattern_names + list_pattern_names + [ 865 "break", "comment", "heading", "defterm", "defterm_empty", 866 "regionend", "rule", 867 ] 868 869 table_row_pattern_names = inline_pattern_names + [ 870 "tableattrs", "tablecell", "tableend" 871 ] 872 873 transclusion_pattern_names = inline_without_links_pattern_names + [ 874 "linksep", "transclusionend"] 875 876 # The region pattern names are specifically used by the common parser 877 # functionality. 878 879 region_pattern_names = region_without_table_pattern_names + ["tablerow"] 880 881 882 883 # Pattern handlers. 884 885 end_region = ParserBase.end_region 886 parse_section_end = ParserBase.parse_region_end 887 888 handlers = { 889 None : end_region, 890 "anchor" : parse_anchor, 891 "attrname" : parse_attrname, 892 "break" : parse_break, 893 "colour" : parse_colour, 894 "colspan" : parse_colspan, 895 "comment" : parse_comment, 896 "defterm" : parse_defterm, 897 "defterm_empty" : parse_defterm_empty, 898 "deftermend" : end_region, 899 "deftermsep" : end_region, 900 "directive" : parse_directive, 901 "fontstyle" : parse_fontstyle, 902 "halign" : parse_halign, 903 "heading" : parse_heading, 904 "headingend" : parse_heading_end, 905 "larger" : parse_larger, 906 "largerend" : end_region, 907 "linebreak" : parse_linebreak, 908 "link" : parse_link, 909 "linkend" : end_region, 910 "linksep" : end_region, 911 "macro" : parse_macro, 912 "listitemend" : end_region, 913 "listitem" : parse_listitem, 914 "listitem_alpha" : parse_listitem, 915 "listitem_dot" : parse_listitem, 916 "listitem_num" : parse_listitem, 917 "listitem_roman" : parse_listitem, 918 "monospace" : parse_monospace, 919 "monospaceend" : end_region, 920 "regionstart" : parse_section, 921 "regionend" : parse_section_end, 922 "rowspan" : parse_rowspan, 923 "rule" : parse_rule, 924 "smaller" : parse_smaller, 925 "smallerend" : end_region, 926 "strike" : parse_strike, 927 "strikeend" : end_region, 928 "sub" : parse_sub, 929 "subend" : end_region, 930 "super" : parse_super, 931 "superend" : end_region, 932 "tableattrs" : parse_table_attrs, 933 "tableattrsend" : end_region, 934 "tablerow" : parse_table_row, 935 "tablecell" : end_region, 936 "tableend" : end_region, 937 "transclusion" : parse_transclusion, 938 "transclusionend" : end_region, 939 "underline" : parse_underline, 940 "underlineend" : end_region, 941 "valign" : parse_valign, 942 "width" : parse_width, 943 } 944 945 parser = MoinParser 946 947 # vim: tabstop=4 expandtab shiftwidth=4