r62813 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r62812‎ | r62813 | r62814 >
Date:05:32, 22 February 2010
Author:than4213
Status:deferred
Tags:
Comment:
Created new rules to take care of Begin of File situations so that ~BOF no longer needs to be prepended to the file
Modified paths:
  • /branches/parser-work/phase3/includes/AutoLoader.php (modified) (history)
  • /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
@@ -1,5 +1,4 @@
22 <?php
3 -
43 /**
54 * Interface for Parse Object each with a specialized task while parsing
65 * @ingroup Parser
@@ -187,36 +186,19 @@
188187 return $this->mName;
189188 }
190189
191 - static function createParseTree($text, $rules) {
192 - wfProfileIn( __METHOD__ );
193 -
194 - $text = "~BOF" . $text;
195 - $retTree = $rules["Root"]->parse($text, $rules);
196 -
197 - wfProfileOut( __METHOD__ );
198 - return $retTree;
199 - }
200 -
201190 //this function will definitely need to be seperated into data and engine layers
202191 function printTree() {
203192 $retString = "";
204193
205194 if ($this->mName == "text") {
206195 $retString = htmlspecialchars($this->mMatches[0]);
207 - } elseif ($this->mName == "commentline") {
208 - $retString = "\n<comment>" . htmlspecialchars($this->mMatches[1]) . "</comment>";
209 - } elseif ($this->mName == "bof") {
210 - if (isset($this->mMatches[1])) {
211 - $retString = "<ignore>" . htmlspecialchars($this->mMatches[1]) . "</ignore>";
212 - }
 196+ } elseif ($this->mName == "newline") {
 197+ $retString = htmlspecialchars($this->mMatches[0]) . $this->mChildren[0]->printTree();
213198 } elseif ($this->mName == "link") {
214199 $retString = htmlspecialchars($this->mMatches[0]) . $this->mChildren[0]->printTree() . "]]";
215200 } elseif ($this->mName == "h") {
216 - $retString = "<h>" . htmlspecialchars($this->mMatches[2]) . $this->mChildren[0]->printTree() .
217 - htmlspecialchars($this->mMatches[2]) . "</h>";
218 - if ($this->mMatches[1] == "\n") {
219 - $retString = "\n" . $retString;
220 - }
 201+ $retString = "<h>" . htmlspecialchars($this->mMatches[0]) . $this->mChildren[0]->printTree() .
 202+ htmlspecialchars($this->mMatches[0]) . "</h>";
221203 } elseif ($this->mName != "unUsed") {
222204 if ($this->mChildren != NULL) {
223205 foreach ($this->mChildren as $crrnt) {
Index: branches/parser-work/phase3/includes/parser/Preprocessor_DOM.php
@@ -74,14 +74,14 @@
7575 "TplArg" => new ParsePattern("tplarg", '/^{{{/s', "TemplateSeq", '}}}'),
7676 "TplPart" => new ParsePattern("part", '/^\|/s', "TplPartList"),
7777 "Link" => new ParsePattern("link", '/^\[\[/s', "MainQuant", ']]'),
78 - "Heading" => new ParsePattern("h", '/^(\n|~BOF)(={1,6})/s', "HeadingQuant", '~2'),
 78+ "NewLine" => new ParsePattern("newline", '/^\n/s', "NewLineChoice"),
 79+ "Heading" => new ParsePattern("h", '/^={1,6}/s', "HeadingQuant", '~0'),
 80+ "CommentLine" => new ParsePattern("commentline", '/^(?:<!--.*?-->\n)+/s'),
7981 "XmlExt" => new ParsePattern("ext", '/^<(?=(' . $xmlishRegex . '))/si', "XmlExtSeq", '~1'),
80 - "CommentLine" => new ParsePattern("commentline", '/^\n((?:<!--.*?-->\n)+)/s'),
8182 "Comment" => new ParsePattern("comment", '/^<!--.*?(?:-->|$)/s'),
8283 "OnlyInclude" => new ParsePattern("ignore", '/^<\/?onlyinclude>/s'),
8384 "NoInclude" => new ParsePattern("ignore", '/^<\/?noinclude>/s'),
8485 "IncludeOnly" => new ParsePattern("ignore", '/^<includeonly>.*?<\/includeonly>/s'),
85 - "BeginFile" => new ParsePattern("bof", '/^~BOF/s'),
8686 "MainText" => new ParsePattern("text", '/^.[^{}\[\]<\n|=]*/s'),
8787 "XmlName" => new ParsePattern("name", '/^.*?(?= |\/>|>)/s'),
8888 "XmlAttr" => new ParsePattern("attr", '/^.*?(?=\/>|>)/s'),
@@ -89,7 +89,8 @@
9090 "XmlOpened" => new ParsePattern("unUsed", '/^>/si'),
9191 "XmlInner" => new ParsePattern("inner", '/^.*?(?=<\/~r>|$)/si'),
9292 "XmlCloseTag" => new ParsePattern("close", '/^<\/~r>/si'),
93 - "Root" => new ParseQuant("root", "MainChoice", '/^$/'),
 93+ "StartQuant" => new ParseQuant("unnamed", "MainChoice", '/^$/'),
 94+ "BOFQuant" => new ParseQuant("unnamed", "NewLineChoice", NULL, 0, 1),
9495 "MainQuant" => new ParseQuant("unnamed", "MainChoice", '/^~r/s'),
9596 "HeadingQuant" => new ParseQuant("unnamed", "MainChoice", '/^~r(?=(?: *<!--.*?-->)*(?:\n|$))/s'),
9697 "TplTitle" => new ParseQuant("title", "MainChoice", '/^(?=~r|\|)/s'),
@@ -98,24 +99,27 @@
99100 "TplName" => new ParseQuant("name", "TplTest", '/^=/s', 0, 1),
100101 "TplValue" => new ParseQuant("value", "MainChoice", '/^(?=~r|\|)/s'),
101102 "XmlCloseQuant" => new ParseQuant("unnamed", "XmlCloseTag", NULL, 0, 1),
102 - "MainChoice" => new ParseChoice("unnamed", array("CurlyChoice", "XmlChoice",
103 - "Heading", "CommentLine", "Link", "BeginFile", "MainText")),
 103+ "MainChoice" => new ParseChoice("unnamed", array("CurlyChoice", "XmlChoice", "NewLine", "Link", "MainText")),
104104 "CurlyChoice" => new ParseChoice("unnamed", array("Template", "TplArg"), "{"),
105105 "XmlChoice" => new ParseChoice("unnamed", array("Comment", "OnlyInclude", "NoInclude", "IncludeOnly", "XmlExt"), "<"),
 106+ "NewLineChoice" => new ParseChoice("unnamed", array("Heading", "CommentLine")),
106107 "TplPartList" => new ParseChoice("unnamed", array("TplPartSeq", "TplValue")),
107108 "XmlClose" => new ParseChoice("unnamed", array("XmlClosed", "XmlOpenedSeq")),
 109+ "StartSeq" => new ParseSeq("root", array("BOFQuant", "StartQuant")),
108110 "TemplateSeq" => new ParseSeq("unnamed", array("TplTitle", "TplPartQuant")),
109111 "TplPartSeq" => new ParseSeq("unnamed", array("TplName", "TplValue")),
110112 "XmlExtSeq" => new ParseSeq("unnamed", array("XmlName", "XmlAttr", "XmlClose")),
111113 "XmlOpenedSeq" => new ParseSeq("unnamed", array("XmlOpened", "XmlInner", "XmlCloseQuant")));
112114 if ($flags & Parser::PTD_FOR_INCLUSION) {
 115+ $rules["BOFQuant"] = new ParseQuant("unnamed", "StartChoice", NULL, 0, 1);
 116+ $rules["StartChoice"] = new ParseChoice("unnamed", array("OnlyIncludeBOF", "NewLineChoice"));
 117+ $rules["OnlyIncludeBOF"] = new ParsePattern("ignore", '/^.*?<onlyinclude>/s');
113118 $rules["OnlyInclude"] = new ParsePattern("ignore", '/^<\/onlyinclude>.*?(?:<onlyinclude>|$)/s');
114119 $rules["NoInclude"] = new ParsePattern("ignore", '/^<noinclude>.*?<\/noinclude>/s');
115120 $rules["IncludeOnly"] = new ParsePattern("ignore", '/^<\/?includeonly>/s');
116 - $rules["BeginFile"] = new ParsePattern("bof", '/^~BOF(.*?<onlyinclude>)?/s');
117121 }
118122
119 - $parseTree = ParseTree::createParseTree($text, $rules);
 123+ $parseTree = $rules["StartSeq"]->parse($text, $rules);
120124 $xml = $parseTree->printTree();
121125
122126 // To DOM
Index: branches/parser-work/phase3/includes/AutoLoader.php
@@ -460,8 +460,11 @@
461461 'PPNode_Hash_Tree' => 'includes/parser/Preprocessor_Hash.php',
462462 'PPTemplateFrame_DOM' => 'includes/parser/Preprocessor_DOM.php',
463463 'PPTemplateFrame_Hash' => 'includes/parser/Preprocessor_Hash.php',
464 - 'ParseList' => 'includes/parser/ParseTree.php',
465 - 'ParseRule' => 'includes/parser/ParseTree.php',
 464+ 'ParseChoice' => 'includes/parser/ParseTree.php',
 465+ 'ParseObject' => 'includes/parser/ParseTree.php',
 466+ 'ParsePattern' => 'includes/parser/ParseTree.php',
 467+ 'ParseQuant' => 'includes/parser/ParseTree.php',
 468+ 'ParseSeq' => 'includes/parser/ParseTree.php',
466469 'ParseTree' => 'includes/parser/ParseTree.php',
467470 'Parser' => 'includes/parser/Parser.php',
468471 'ParserCache' => 'includes/parser/ParserCache.php',

Status & tagging log