Index: branches/parser-work/phase3/includes/parser/Parser.php |
— | — | @@ -2788,6 +2788,17 @@ |
2789 | 2789 | $this->addTrackingCategory( "$limitationType-category" ); |
2790 | 2790 | } |
2791 | 2791 | |
| 2792 | + function transformParseDom($inNode) { |
| 2793 | + if ($inNode->nodeName == "newLine") { |
| 2794 | + $inNode->setAttribute("tag", "\n"); |
| 2795 | + } |
| 2796 | + foreach ($inNode->childNodes as $child) { |
| 2797 | + if ($child instanceof DOMElement) { |
| 2798 | + $this->transformParseDom($child); |
| 2799 | + } |
| 2800 | + } |
| 2801 | + } |
| 2802 | + |
2792 | 2803 | /** |
2793 | 2804 | * Return the text of a template, after recursively |
2794 | 2805 | * replacing any variables or templates within the template. |
— | — | @@ -3965,23 +3976,19 @@ |
3966 | 3977 | * @param Title &$title the Title object for the current article |
3967 | 3978 | * @param User $user the User object describing the current user |
3968 | 3979 | * @param ParserOptions $options parsing options |
3969 | | - * @param bool $clearState whether to clear the parser state first |
3970 | 3980 | * @return string the altered wiki markup |
3971 | 3981 | * @public |
3972 | 3982 | */ |
3973 | | - function preSaveTransform( $text, Title $title, $user, $options, $clearState = true ) { |
| 3983 | + function preSaveTransform( $text, Title $title, $user, $options ) { |
3974 | 3984 | $this->mOptions = $options; |
3975 | 3985 | $this->setTitle( $title ); |
3976 | 3986 | $this->setOutputType( self::OT_WIKI ); |
| 3987 | + $this->clearState(); |
3977 | 3988 | |
3978 | | - if ( $clearState ) { |
3979 | | - $this->clearState(); |
3980 | | - } |
3981 | | - |
3982 | | - $pairs = array( |
3983 | | - "\r\n" => "\n", |
3984 | | - ); |
3985 | | - $text = str_replace( array_keys( $pairs ), array_values( $pairs ), $text ); |
| 3989 | + $parser = new ParseEngine("includes/parser/WikiTextGrammar.xml"); |
| 3990 | + $dom = $parser->parse($text); |
| 3991 | + $this->transformParseDom($dom->documentElement); |
| 3992 | + $text = ParseEngine::unparse($dom->documentElement); |
3986 | 3993 | $text = $this->pstPass2( $text, $user ); |
3987 | 3994 | $text = $this->mStripState->unstripBoth( $text ); |
3988 | 3995 | return $text; |
Index: branches/parser-work/phase3/includes/parser/ParseEngine.php |
— | — | @@ -8,7 +8,7 @@ |
9 | 9 | */ |
10 | 10 | class ParseEngine { |
11 | 11 | const maxIter = 2048; |
12 | | - private $mGrammar, $mTextPats; |
| 12 | + private $mGrammar; |
13 | 13 | |
14 | 14 | function __construct($grammarFile) { |
15 | 15 | global $IP; |
— | — | @@ -43,24 +43,15 @@ |
44 | 44 | return $doc; |
45 | 45 | } |
46 | 46 | |
47 | | - static function expand($nodeList, $callback, $flags = 0) { |
48 | | - $retStr = ""; |
49 | | - foreach ($nodeList as $node) { |
50 | | - if ($node instanceof DOMText) { |
51 | | - $retStr .= $node->data; |
| 47 | + static function unparse($inNode) { |
| 48 | + $retStr = "" . $inNode->getAttribute("tag"); |
| 49 | + foreach ($inNode->childNodes as $child) { |
| 50 | + if ($child instanceof DOMText) { |
| 51 | + $retStr .= $child->data; |
52 | 52 | } else { |
53 | | - $methodName = $node->nodeName . "Substitution"; |
54 | | - if (method_exists($callback, $methodName) && call_user_func_array(array($callback, $methodName), array($node, &$outStr, $flags))) { |
55 | | - $retStr .= $outStr; |
56 | | - } else { |
57 | | - $retStr .= $node->getAttribute("tag") . self::expand($node->childNodes, $callback, $flags); |
58 | | - } |
| 53 | + $retStr .= self::unparse($child); |
59 | 54 | } |
60 | 55 | } |
61 | | - global $wgDebugParserLog; |
62 | | - if ($wgDebugParserLog != '') { |
63 | | - wfErrorLog("Expand returned: $retStr\n", $wgDebugParserLog); |
64 | | - } |
65 | 56 | return $retStr; |
66 | 57 | } |
67 | 58 | |
Index: branches/parser-work/phase3/includes/parser/WikiTextGrammar.xml |
— | — | @@ -1,19 +1,14 @@ |
2 | 2 | <?xml version="1.0"?> |
3 | | -<Grammar rootTag="root" startRule="start"> |
| 3 | +<Grammar rootTag="root" startRule="start" version="1.0"> |
4 | 4 | <Sequence name="start" > |
5 | | - <Choice failSafe="true"> |
6 | | - <Assignment tagName="onlyInclude" tag="(?=.*(<onlyinclude>))" regex="true"> |
7 | | - <Reference name="endText" /> |
8 | | - </Assignment> |
9 | | - <Reference name="postNewline" /> |
10 | | - </Choice> |
| 5 | + <Reference name="postNewLine" /> |
11 | 6 | <Reference name="main" /> |
12 | 7 | </Sequence> |
13 | 8 | <Text name="main"> |
14 | 9 | <Choice> |
15 | 10 | <Sequence> |
16 | | - <Reference name="newline" /> |
17 | | - <Reference name="postNewline" /> |
| 11 | + <Reference name="newLine" /> |
| 12 | + <Reference name="postNewLine" /> |
18 | 13 | </Sequence> |
19 | 14 | <Assignment tagName="link" tag="[["> |
20 | 15 | <Reference name="endText" var="]]" /> |
— | — | @@ -37,14 +32,6 @@ |
38 | 33 | </Sequence> |
39 | 34 | </Assignment> |
40 | 35 | <Reference name="comment" /> |
41 | | - <Assignment tagName="onlyInclude" tag="</onlyinclude>"> |
42 | | - <Sequence> |
43 | | - <Reference name="main" /> |
44 | | - <Choice failSafe="true"> |
45 | | - <Assignment tagName="endTag" tag="<onlyinclude>" /> |
46 | | - </Choice> |
47 | | - </Sequence> |
48 | | - </Assignment> |
49 | 36 | <Assignment tagName="noWiki" tag="<nowiki>"> |
50 | 37 | <Sequence> |
51 | 38 | <Text /> |
— | — | @@ -72,7 +59,7 @@ |
73 | 60 | <Reference name="main" /> |
74 | 61 | <Assignment tagName="endTag" tag="~r" /> |
75 | 62 | </Sequence> |
76 | | - <Assignment name="newline" tagName="newLine" tag=" " /> |
| 63 | + <Assignment name="newLine" tagName="newLine" tag="\r?\n" regex="true" /> |
77 | 64 | <Assignment name="eol" tagName="eol" tag="(?=\n|$)" regex="true" /> |
78 | 65 | <Choice name="ignoreList" failSafe="true"> |
79 | 66 | <Sequence> |
— | — | @@ -83,7 +70,7 @@ |
84 | 71 | <Reference name="ignoreList" /> |
85 | 72 | </Sequence> |
86 | 73 | </Choice> |
87 | | - <Choice name="postNewline" failSafe="true"> |
| 74 | + <Choice name="postNewLine" failSafe="true"> |
88 | 75 | <Sequence> |
89 | 76 | <Assignment tagName="h" tag="(={1,6})" regex="true"> |
90 | 77 | <Reference name="endText" /> |
— | — | @@ -113,7 +100,7 @@ |
114 | 101 | </Choice> |
115 | 102 | <Choice failSafe="true"> |
116 | 103 | <Sequence> |
117 | | - <Reference name="newline" /> |
| 104 | + <Reference name="newLine" /> |
118 | 105 | <Reference name="itemList" /> |
119 | 106 | </Sequence> |
120 | 107 | </Choice> |
Index: branches/parser-work/phase3/includes/AutoLoader.php |
— | — | @@ -463,6 +463,7 @@ |
464 | 464 | 'PPNode_Hash_Tree' => 'includes/parser/Preprocessor_Hash.php', |
465 | 465 | 'PPTemplateFrame_DOM' => 'includes/parser/Preprocessor_DOM.php', |
466 | 466 | 'PPTemplateFrame_Hash' => 'includes/parser/Preprocessor_Hash.php', |
| 467 | + 'ParseEngine' => 'includes/parser/ParseEngine.php', |
467 | 468 | 'Parser' => 'includes/parser/Parser.php', |
468 | 469 | 'ParserCache' => 'includes/parser/ParserCache.php', |
469 | 470 | 'ParserOptions' => 'includes/parser/ParserOptions.php', |