Index: branches/parser-work/phase3/includes/parser/ParseTree.php |
— | — | @@ -112,7 +112,7 @@ |
113 | 113 | wfProfileIn( __METHOD__ ); |
114 | 114 | |
115 | 115 | $text = "~BOF" . $text; |
116 | | - $root = new ParseRule("Root", '/^/', '/^\Z/'); |
| 116 | + $root = new ParseRule("root", '/^/', '/^\Z/'); |
117 | 117 | $retTree = $root->parse($text, $parseList); |
118 | 118 | |
119 | 119 | wfProfileOut( __METHOD__ ); |
— | — | @@ -123,29 +123,26 @@ |
124 | 124 | function printTree() { |
125 | 125 | $retString = ""; |
126 | 126 | |
127 | | - if ($this->mName == "Literal" || $this->mName == "BugHHP21") { |
| 127 | + if ($this->mName == "hhp21") { |
128 | 128 | $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") { |
132 | 130 | $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") { |
146 | 132 | if (isset($this->mMatches[1])) { |
147 | 133 | $retString = "<ignore>" . htmlspecialchars($this->mMatches[1]) . "</ignore>"; |
148 | 134 | } |
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])) { |
150 | 147 | $inTitle = true; |
151 | 148 | $foundEquals = false; |
152 | 149 | $currentItem = ""; |
— | — | @@ -173,11 +170,7 @@ |
174 | 171 | $currentItem .= htmlspecialchars($crrnt); |
175 | 172 | } |
176 | 173 | } |
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 . ">"; |
182 | 175 | } else { |
183 | 176 | foreach ($this->mChildren as $crrnt) { |
184 | 177 | if ($crrnt instanceof ParseTree) { |
— | — | @@ -186,18 +179,16 @@ |
187 | 180 | $retString .= htmlspecialchars($crrnt); |
188 | 181 | } |
189 | 182 | } |
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") { |
193 | 186 | $retString = htmlspecialchars($this->mMatches[0]) . $retString; |
194 | | - } elseif ($this->mName == "Template") { |
195 | | - $retString = "{{" . $retString; |
196 | | - } elseif ($this->mName == "Link") { |
| 187 | + } elseif ($this->mName == "link") { |
197 | 188 | $retString = htmlspecialchars($this->mMatches[0]) . $retString; |
198 | 189 | if (isset($this->mMatches[1])) { |
199 | 190 | $retString .= htmlspecialchars($this->mMatches[1]); |
200 | 191 | } |
201 | | - } elseif ($this->mName == "Heading") { |
| 192 | + } elseif ($this->mName == "h") { |
202 | 193 | $retString = htmlspecialchars($this->mMatches[2]) . $retString; |
203 | 194 | if (isset($this->mMatches[3])) { |
204 | 195 | $retString = "<h>" . $retString . htmlspecialchars($this->mMatches[3]) . "</h>"; |
Index: branches/parser-work/phase3/includes/parser/Preprocessor_DOM.php |
— | — | @@ -69,26 +69,25 @@ |
70 | 70 | |
71 | 71 | // To XML |
72 | 72 | $xmlishRegex = implode('|', $this->parser->getStripList()); |
73 | | - $bugHHP21 = new ParseRule("BugHHP21", '/^\n(?==[^=])/s'); |
| 73 | + $bugHHP21 = new ParseRule("hhp21", '/^\n(?==[^=])/s'); |
74 | 74 | $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')); |
88 | 87 | 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'); |
93 | 92 | } |
94 | 93 | |
95 | 94 | $parseList = new ParseList($rules, '{\[<\n'); |