Index: branches/parser-work/phase3/includes/parser/ParseTree.php |
— | — | @@ -1,5 +1,4 @@ |
2 | 2 | <?php |
3 | | - |
4 | 3 | /** |
5 | 4 | * Interface for Parse Object each with a specialized task while parsing |
6 | 5 | * @ingroup Parser |
— | — | @@ -187,36 +186,19 @@ |
188 | 187 | return $this->mName; |
189 | 188 | } |
190 | 189 | |
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 | | - |
201 | 190 | //this function will definitely need to be seperated into data and engine layers |
202 | 191 | function printTree() { |
203 | 192 | $retString = ""; |
204 | 193 | |
205 | 194 | if ($this->mName == "text") { |
206 | 195 | $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(); |
213 | 198 | } elseif ($this->mName == "link") { |
214 | 199 | $retString = htmlspecialchars($this->mMatches[0]) . $this->mChildren[0]->printTree() . "]]"; |
215 | 200 | } 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>"; |
221 | 203 | } elseif ($this->mName != "unUsed") { |
222 | 204 | if ($this->mChildren != NULL) { |
223 | 205 | foreach ($this->mChildren as $crrnt) { |
Index: branches/parser-work/phase3/includes/parser/Preprocessor_DOM.php |
— | — | @@ -74,14 +74,14 @@ |
75 | 75 | "TplArg" => new ParsePattern("tplarg", '/^{{{/s', "TemplateSeq", '}}}'), |
76 | 76 | "TplPart" => new ParsePattern("part", '/^\|/s', "TplPartList"), |
77 | 77 | "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'), |
79 | 81 | "XmlExt" => new ParsePattern("ext", '/^<(?=(' . $xmlishRegex . '))/si', "XmlExtSeq", '~1'), |
80 | | - "CommentLine" => new ParsePattern("commentline", '/^\n((?:<!--.*?-->\n)+)/s'), |
81 | 82 | "Comment" => new ParsePattern("comment", '/^<!--.*?(?:-->|$)/s'), |
82 | 83 | "OnlyInclude" => new ParsePattern("ignore", '/^<\/?onlyinclude>/s'), |
83 | 84 | "NoInclude" => new ParsePattern("ignore", '/^<\/?noinclude>/s'), |
84 | 85 | "IncludeOnly" => new ParsePattern("ignore", '/^<includeonly>.*?<\/includeonly>/s'), |
85 | | - "BeginFile" => new ParsePattern("bof", '/^~BOF/s'), |
86 | 86 | "MainText" => new ParsePattern("text", '/^.[^{}\[\]<\n|=]*/s'), |
87 | 87 | "XmlName" => new ParsePattern("name", '/^.*?(?= |\/>|>)/s'), |
88 | 88 | "XmlAttr" => new ParsePattern("attr", '/^.*?(?=\/>|>)/s'), |
— | — | @@ -89,7 +89,8 @@ |
90 | 90 | "XmlOpened" => new ParsePattern("unUsed", '/^>/si'), |
91 | 91 | "XmlInner" => new ParsePattern("inner", '/^.*?(?=<\/~r>|$)/si'), |
92 | 92 | "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), |
94 | 95 | "MainQuant" => new ParseQuant("unnamed", "MainChoice", '/^~r/s'), |
95 | 96 | "HeadingQuant" => new ParseQuant("unnamed", "MainChoice", '/^~r(?=(?: *<!--.*?-->)*(?:\n|$))/s'), |
96 | 97 | "TplTitle" => new ParseQuant("title", "MainChoice", '/^(?=~r|\|)/s'), |
— | — | @@ -98,24 +99,27 @@ |
99 | 100 | "TplName" => new ParseQuant("name", "TplTest", '/^=/s', 0, 1), |
100 | 101 | "TplValue" => new ParseQuant("value", "MainChoice", '/^(?=~r|\|)/s'), |
101 | 102 | "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")), |
104 | 104 | "CurlyChoice" => new ParseChoice("unnamed", array("Template", "TplArg"), "{"), |
105 | 105 | "XmlChoice" => new ParseChoice("unnamed", array("Comment", "OnlyInclude", "NoInclude", "IncludeOnly", "XmlExt"), "<"), |
| 106 | + "NewLineChoice" => new ParseChoice("unnamed", array("Heading", "CommentLine")), |
106 | 107 | "TplPartList" => new ParseChoice("unnamed", array("TplPartSeq", "TplValue")), |
107 | 108 | "XmlClose" => new ParseChoice("unnamed", array("XmlClosed", "XmlOpenedSeq")), |
| 109 | + "StartSeq" => new ParseSeq("root", array("BOFQuant", "StartQuant")), |
108 | 110 | "TemplateSeq" => new ParseSeq("unnamed", array("TplTitle", "TplPartQuant")), |
109 | 111 | "TplPartSeq" => new ParseSeq("unnamed", array("TplName", "TplValue")), |
110 | 112 | "XmlExtSeq" => new ParseSeq("unnamed", array("XmlName", "XmlAttr", "XmlClose")), |
111 | 113 | "XmlOpenedSeq" => new ParseSeq("unnamed", array("XmlOpened", "XmlInner", "XmlCloseQuant"))); |
112 | 114 | 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'); |
113 | 118 | $rules["OnlyInclude"] = new ParsePattern("ignore", '/^<\/onlyinclude>.*?(?:<onlyinclude>|$)/s'); |
114 | 119 | $rules["NoInclude"] = new ParsePattern("ignore", '/^<noinclude>.*?<\/noinclude>/s'); |
115 | 120 | $rules["IncludeOnly"] = new ParsePattern("ignore", '/^<\/?includeonly>/s'); |
116 | | - $rules["BeginFile"] = new ParsePattern("bof", '/^~BOF(.*?<onlyinclude>)?/s'); |
117 | 121 | } |
118 | 122 | |
119 | | - $parseTree = ParseTree::createParseTree($text, $rules); |
| 123 | + $parseTree = $rules["StartSeq"]->parse($text, $rules); |
120 | 124 | $xml = $parseTree->printTree(); |
121 | 125 | |
122 | 126 | // To DOM |
Index: branches/parser-work/phase3/includes/AutoLoader.php |
— | — | @@ -460,8 +460,11 @@ |
461 | 461 | 'PPNode_Hash_Tree' => 'includes/parser/Preprocessor_Hash.php', |
462 | 462 | 'PPTemplateFrame_DOM' => 'includes/parser/Preprocessor_DOM.php', |
463 | 463 | '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', |
466 | 469 | 'ParseTree' => 'includes/parser/ParseTree.php', |
467 | 470 | 'Parser' => 'includes/parser/Parser.php', |
468 | 471 | 'ParserCache' => 'includes/parser/ParserCache.php', |