r62602 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62601‎ | r62602 | r62603 >
Date:22:05, 16 February 2010
Author:than4213
Status:deferred
Tags:
Comment:
index rules by name and have the parser tag match the xml tag
Modified paths:
  • /branches/parser-work/phase3/includes/parser/ParseTree.php (modified) (history)
  • /branches/parser-work/phase3/includes/parser/Preprocessor_DOM.php (modified) (history)

Diff [purge]

Index: branches/parser-work/phase3/includes/parser/ParseTree.php
@@ -112,7 +112,7 @@
113113 wfProfileIn( __METHOD__ );
114114
115115 $text = "~BOF" . $text;
116 - $root = new ParseRule("Root", '/^/', '/^\Z/');
 116+ $root = new ParseRule("root", '/^/', '/^\Z/');
117117 $retTree = $root->parse($text, $parseList);
118118
119119 wfProfileOut( __METHOD__ );
@@ -123,29 +123,26 @@
124124 function printTree() {
125125 $retString = "";
126126
127 - if ($this->mName == "Literal" || $this->mName == "BugHHP21") {
 127+ if ($this->mName == "hhp21") {
128128 $retString = htmlspecialchars($this->mMatches[0]);
129 - } elseif ($this->mName == "Comment") {
130 - $retString = "<comment>" . htmlspecialchars($this->mMatches[0]) . "</comment>";
131 - } elseif ($this->mName == "CommentLine") {
 129+ } elseif ($this->mName == "commentline") {
132130 $retString = htmlspecialchars($this->mMatches[1]) . "<comment>" . htmlspecialchars($this->mMatches[2]) . "</comment>";
133 - } elseif ($this->mName == "IncludeOnly" || $this->mName == "NoInclude" || $this->mName == "OnlyInclude") {
134 - $retString = "<ignore>" . htmlspecialchars($this->mMatches[0]) . "</ignore>";
135 - } elseif ($this->mName == "XmlClosed") {
136 - $retString = "<ext><name>" . htmlspecialchars($this->mMatches[1]) .
137 - "</name><attr>" . htmlspecialchars($this->mMatches[2]) . "</attr></ext>";
138 - } elseif ($this->mName == "XmlOpened") {
139 - $closeTag = "";
140 - if ($this->mMatches[4] != "") {
141 - $closeTag = "<close>" . htmlspecialchars($this->mMatches[4]) . "</close>";
142 - }
143 - $retString = "<ext><name>" . htmlspecialchars($this->mMatches[1]) . "</name><attr>" . htmlspecialchars($this->mMatches[2]) .
144 - "</attr><inner>" . htmlspecialchars($this->mMatches[3]) . "</inner>" . $closeTag . "</ext>";
145 - } elseif ($this->mName == "BeginFile") {
 131+ } elseif ($this->mName == "bof") {
146132 if (isset($this->mMatches[1])) {
147133 $retString = "<ignore>" . htmlspecialchars($this->mMatches[1]) . "</ignore>";
148134 }
149 - } elseif (($this->mName == "Template" || $this->mName == "TplArg") && isset($this->mMatches[1])) {
 135+ } elseif ($this->mName == "comment" || $this->mName == "ignore") {
 136+ $retString = "<" . $this->mName . ">" . htmlspecialchars($this->mMatches[0]) . "</" . $this->mName . ">";
 137+ } elseif ($this->mName == "ext") {
 138+ $retString = "<name>" . htmlspecialchars($this->mMatches[1]) . "</name><attr>" . htmlspecialchars($this->mMatches[2]) . "</attr>";
 139+ if (isset($this->mMatches[3])) {
 140+ $retString .= "<inner>" . htmlspecialchars($this->mMatches[3]) . "</inner>";
 141+ }
 142+ if (isset($this->mMatches[4])) {
 143+ $retString .= "<close>" . htmlspecialchars($this->mMatches[4]) . "</close>";
 144+ }
 145+ $retString = "<" . $this->mName . ">" . $retString . "</" . $this->mName . ">";
 146+ } elseif (($this->mName == "template" || $this->mName == "tplarg") && isset($this->mMatches[1])) {
150147 $inTitle = true;
151148 $foundEquals = false;
152149 $currentItem = "";
@@ -173,11 +170,7 @@
174171 $currentItem .= htmlspecialchars($crrnt);
175172 }
176173 }
177 - if ($this->mName == "Template") {
178 - $retString = "<template>" . $retString . "</template>";
179 - } else {
180 - $retString = "<tplarg>" . $retString . "</tplarg>";
181 - }
 174+ $retString = "<" . $this->mName . ">" . $retString . "</" . $this->mName . ">";
182175 } else {
183176 foreach ($this->mChildren as $crrnt) {
184177 if ($crrnt instanceof ParseTree) {
@@ -186,18 +179,16 @@
187180 $retString .= htmlspecialchars($crrnt);
188181 }
189182 }
190 - if ($this->mName == "Root") {
191 - $retString = "<root>" . $retString . "</root>";
192 - } elseif ($this->mName == "TplArg") {
 183+ if ($this->mName == "root") {
 184+ $retString = "<" . $this->mName . ">" . $retString . "</" . $this->mName . ">";
 185+ } elseif ($this->mName == "tplarg" || $this->mName == "template") {
193186 $retString = htmlspecialchars($this->mMatches[0]) . $retString;
194 - } elseif ($this->mName == "Template") {
195 - $retString = "{{" . $retString;
196 - } elseif ($this->mName == "Link") {
 187+ } elseif ($this->mName == "link") {
197188 $retString = htmlspecialchars($this->mMatches[0]) . $retString;
198189 if (isset($this->mMatches[1])) {
199190 $retString .= htmlspecialchars($this->mMatches[1]);
200191 }
201 - } elseif ($this->mName == "Heading") {
 192+ } elseif ($this->mName == "h") {
202193 $retString = htmlspecialchars($this->mMatches[2]) . $retString;
203194 if (isset($this->mMatches[3])) {
204195 $retString = "<h>" . $retString . htmlspecialchars($this->mMatches[3]) . "</h>";
Index: branches/parser-work/phase3/includes/parser/Preprocessor_DOM.php
@@ -69,26 +69,25 @@
7070
7171 // To XML
7272 $xmlishRegex = implode('|', $this->parser->getStripList());
73 - $bugHHP21 = new ParseRule("BugHHP21", '/^\n(?==[^=])/s');
 73+ $bugHHP21 = new ParseRule("hhp21", '/^\n(?==[^=])/s');
7474 $rules = array(
75 - new ParseRule("Template", '/^{{(?!{[^{])/s', '/^}}/s', '}|=', $bugHHP21),
76 - new ParseRule("TplArg", '/^{{{/s', '/^}}}/s', '}|=', $bugHHP21),
77 - new ParseRule("Link", '/^\[\[/s', '/^]]/s', '\]'),
78 - new ParseRule("Heading", '/^(\n|~BOF)(={1,6})/s', '/^~2(?: *<!--.*?(?:-->|\Z))*(?=\n|$)/s', '='),
79 - new ParseRule("CommentLine", '/^(\n *)((?:<!--.*?(?:-->|$)(?: *\n)?)+)/s'),
80 - new ParseRule("Comment", '/^<!--.*?(?:-->|$)/s'),
81 - new ParseRule("OnlyInclude", '/^<\/?onlyinclude>/s'),
82 - new ParseRule("NoInclude", '/^<\/?noinclude>/s'),
83 - new ParseRule("IncludeOnly", '/^<includeonly>.*?(?:<\/includeonly>|$)/s'),
84 - new ParseRule("XmlClosed", '/^<(' . $xmlishRegex . ')([^>]*)\/>/si'),
85 - new ParseRule("XmlOpened", '/^<(' . $xmlishRegex . ')(.*?)>(.*?)(<\/\1>|$)/si'),
86 - new ParseRule("BeginFile", '/^~BOF/s'));
87 -
 75+ "Template" => new ParseRule("template", '/^{{(?!{[^{])/s', '/^}}/s', '}|=', $bugHHP21),
 76+ "TplArg" => new ParseRule("tplarg", '/^{{{/s', '/^}}}/s', '}|=', $bugHHP21),
 77+ "Link" => new ParseRule("link", '/^\[\[/s', '/^]]/s', '\]'),
 78+ "Heading" => new ParseRule("h", '/^(\n|~BOF)(={1,6})/s', '/^~2(?: *<!--.*?(?:-->|\Z))*(?=\n|$)/s', '='),
 79+ "CommentLine" => new ParseRule("commentline", '/^(\n *)((?:<!--.*?(?:-->|$)(?: *\n)?)+)/s'),
 80+ "Comment" => new ParseRule("comment", '/^<!--.*?(?:-->|$)/s'),
 81+ "OnlyInclude" => new ParseRule("ignore", '/^<\/?onlyinclude>/s'),
 82+ "NoInclude" => new ParseRule("ignore", '/^<\/?noinclude>/s'),
 83+ "IncludeOnly" => new ParseRule("ignore", '/^<includeonly>.*?(?:<\/includeonly>|$)/s'),
 84+ "XmlClosed" => new ParseRule("ext", '/^<(' . $xmlishRegex . ')([^>]*)\/>/si'),
 85+ "XmlOpened" => new ParseRule("ext", '/^<(' . $xmlishRegex . ')(.*?)>(.*?)(<\/\1>|$)/si'),
 86+ "BeginFile" => new ParseRule("bof", '/^~BOF/s'));
8887 if ($flags & Parser::PTD_FOR_INCLUSION) {
89 - $rules[6] = new ParseRule("OnlyInclude", '/^<\/onlyinclude>.*?(?:<onlyinclude>|$)/s');
90 - $rules[7] = new ParseRule("NoInclude", '/^<noinclude>.*?(?:<\/noinclude>|$)/s');
91 - $rules[8] = new ParseRule("IncludeOnly", '/^<\/?includeonly>/s');
92 - $rules[11] = new ParseRule("BeginFile", '/^~BOF(.*?<onlyinclude>)?/s');
 88+ $rules["OnlyInclude"] = new ParseRule("ignore", '/^<\/onlyinclude>.*?(?:<onlyinclude>|$)/s');
 89+ $rules["NoInclude"] = new ParseRule("ignore", '/^<noinclude>.*?(?:<\/noinclude>|$)/s');
 90+ $rules["IncludeOnly"] = new ParseRule("ignore", '/^<\/?includeonly>/s');
 91+ $rules["BeginFile"] = new ParseRule("bof", '/^~BOF(.*?<onlyinclude>)?/s');
9392 }
9493
9594 $parseList = new ParseList($rules, '{\[<\n');

Status & tagging log