Parent Directory
|
Revision Log
|
Patch
| revision 1.14 by wakaba, Tue Apr 29 02:50:00 2008 UTC | revision 1.18 by wakaba, Sun Aug 31 09:46:14 2008 UTC | |
|---|---|---|
| # | Line 65 | Line 65 |
| 65 | ||
| 66 | var logIndentLevel = 0; | var logIndentLevel = 0; |
| 67 | function log (s) { | function log (s) { |
| 68 | var indent = ''; | |
| 69 | for (var i = 0; i < logIndentLevel; i++) { | for (var i = 0; i < logIndentLevel; i++) { |
| 70 | s = ' ' + s; | indent += ' '; |
| 71 | } | } |
| 72 | s = indent + s.replace (/\n/g, "\n" + indent); | |
| 73 | document.logElement.appendChild (document.createTextNode (s + "\n")); | document.logElement.appendChild (document.createTextNode (s + "\n")); |
| 74 | } // log | } // log |
| 75 | ||
| # | Line 81 | Line 83 |
| 83 | doc = new JSDocument (this); | doc = new JSDocument (this); |
| 84 | doc.manakaiIsHTML = true; | doc.manakaiIsHTML = true; |
| 85 | } | } |
| 86 | this.nextToken = []; | |
| 87 | this.doc = doc; | this.doc = doc; |
| 88 | this.openElements = [doc]; | this.openElements = [doc]; |
| 89 | this.input = i; | this.input = i; |
| # | Line 90 | Line 93 |
| 93 | } // Parser | } // Parser |
| 94 | ||
| 95 | Parser.prototype.getNextToken = function () { | Parser.prototype.getNextToken = function () { |
| 96 | if (this.nextToken.length) { | |
| 97 | return this.nextToken.shift (); | |
| 98 | } | |
| 99 | ||
| 100 | var p = this; | var p = this; |
| 101 | var i = this.input; | var i = this.input; |
| 102 | if (this.parseMode == 'cdata') { | if (this.parseMode == 'cdata') { |
| # | Line 144 | Line 151 |
| 151 | i.s = i.s.replace (/^<\/([^>]+)(?:>|$)/, function (s, e) { | i.s = i.s.replace (/^<\/([^>]+)(?:>|$)/, function (s, e) { |
| 152 | if (p.insertionPoint < s.length || | if (p.insertionPoint < s.length || |
| 153 | (p.insertionPoint <= s.length && | (p.insertionPoint <= s.length && |
| 154 | s.substring (s.length - 1, 1) != '>')) { | s.substring (s.length - 1, s.length) != '>')) { |
| 155 | token = {type: 'abort'}; | token = {type: 'abort'}; |
| 156 | return s; | return s; |
| 157 | } | } |
| # | Line 156 | Line 163 |
| 163 | i.s = i.s.replace (/^<([^>]+)(?:>|$)/, function (s, e) { | i.s = i.s.replace (/^<([^>]+)(?:>|$)/, function (s, e) { |
| 164 | if (p.insertionPoint < s.length || | if (p.insertionPoint < s.length || |
| 165 | (p.insertionPoint <= s.length && | (p.insertionPoint <= s.length && |
| 166 | s.substring (s.length - 1, 1) != '>')) { | s.substring (s.length - 1, s.length) != '>')) { |
| 167 | token = {type: 'abort'}; | token = {type: 'abort'}; |
| 168 | return s; | return s; |
| 169 | } | } |
| # | Line 219 | Line 226 |
| 226 | var token = this.getNextToken (); | var token = this.getNextToken (); |
| 227 | log ('token: ' + token.type + ' "' + token.value + '"'); | log ('token: ' + token.type + ' "' + token.value + '"'); |
| 228 | ||
| 229 | if (this.cdataEndTagRequired) { | |
| 230 | // Generic CDATA parsing algorithm | |
| 231 | ||
| 232 | if (token.type != 'abort') { | |
| 233 | // 7. | |
| 234 | if (token.type == 'end-tag' && token.value == this.endTagName) { | |
| 235 | // 7.1. Ignores it. | |
| 236 | // | |
| 237 | } else { | |
| 238 | // 7.2. Parse error. | |
| 239 | log ('Parse error: no </' + this.endTagName + '>'); | |
| 240 | this.nextToken.unshift (token); | |
| 241 | } | |
| 242 | this.cdataEndTagRequired = false; | |
| 243 | continue; | |
| 244 | } | |
| 245 | } | |
| 246 | ||
| 247 | if (token.type == 'start-tag') { | if (token.type == 'start-tag') { |
| 248 | if (token.value == 'script') { | if (token.value == 'script') { |
| 249 | // 1. Create an element for the token in the HTML namespace. | // 1. Create an element for the token in the HTML namespace. |
| # | Line 255 | Line 280 |
| 280 | if (!(token.type == 'end-tag' && token.value == 'script')) { | if (!(token.type == 'end-tag' && token.value == 'script')) { |
| 281 | // 7.2. This is a parse error. | // 7.2. This is a parse error. |
| 282 | log ('Parse error: no </' + 'script>'); | log ('Parse error: no </' + 'script>'); |
| 283 | this.nextToken.unshift (token); | |
| 284 | ||
| 285 | // 7.3. Mark the script element as "already executed". | // 7.3. Mark the script element as "already executed". |
| 286 | el.manakaiAlreadyExecuted = true; | el.manakaiAlreadyExecuted = true; |
| # | Line 286 | Line 312 |
| 312 | oldInsertionPoint += this.insertionPoint; | oldInsertionPoint += this.insertionPoint; |
| 313 | this.setInsertionPoint (oldInsertionPoint); | this.setInsertionPoint (oldInsertionPoint); |
| 314 | ||
| 315 | // 12. If there is a script that will execute as soon as ... | // 12. If there is a pending external script |
| 316 | while (this.scriptExecutedWhenParserResumes) { | while (this.pendingExternalScript) { |
| 317 | // 12.1. If the tree construction stage is being called reentrantly | // 12.1. If the tree construction stage is being called reentrantly |
| 318 | if (this.reentrant) { | if (this.reentrant) { |
| 319 | log ('parse: abort (reentrance)'); | log ('parse: abort (reentrance)'); |
| # | Line 297 | Line 323 |