/[suikacvs]/markup/html/scripting-parser/parser.html
Suika

Diff of /markup/html/scripting-parser/parser.html

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by wakaba, Fri Apr 25 11:40:56 2008 UTC revision 1.6 by wakaba, Fri Apr 25 13:42:51 2008 UTC
# Line 26  Line 26 
26      log (dumpTree (doc, ''));      log (dumpTree (doc, ''));
27    } // update    } // update
28    
29      var logIndentLevel = 0;
30    function log (s) {    function log (s) {
31        for (var i = 0; i < logIndentLevel; i++) {
32          s = '  ' + s;
33        }
34      document.logElement.appendChild (document.createTextNode (s + "\n"));      document.logElement.appendChild (document.createTextNode (s + "\n"));
35    } // log    } // log
36    
# Line 121  Line 125 
125          tagName = v.toLowerCase ();          tagName = v.toLowerCase ();
126          return '';          return '';
127        });        });
128        e = e.replace (/^\s*(\S+)\s*(?:=\s*"([^"]*)"|'([^']*)'|([^"']+))?/,        e = e.replace (/^\s*([^\s=]+)\s*(?:=\s*(?:"([^"]*)"|'([^']*)'|([^"']+)))?/,
129        function (x, attrName, attrValue1, attrValue2, attrValue3) {        function (x, attrName, attrValue1, attrValue2, attrValue3) {
130          attrs[attrName] = attrValue1 || attrValue2 || attrValue3;          v = attrValue1 || attrValue2 || attrValue3;
131            v = v.replace (/&quot;/g, '"').replace (/&apos;/g, "'")
132                .replace (/&amp;/g, '&');
133            attrs[attrName.toLowerCase ()] = v;
134          return '';          return '';
135        });        });
136          if (e.length) {
137            log ('Broken start tag: "' + e + '"');
138          }
139        token = {type: 'start-tag', value: tagName, attrs: attrs};        token = {type: 'start-tag', value: tagName, attrs: attrs};
140        p.insertionPoint -= s.length;        p.insertionPoint -= s.length;
141        return '';        return '';
# Line 156  Line 166 
166    } // getNextToken    } // getNextToken
167    
168    Parser.prototype.parse = function () {    Parser.prototype.parse = function () {
169      log ('start parsing');      logIndentLevel++;
170        log ('parse: start');
171    
172      while (true) {      while (true) {
173        var token = this.getNextToken ();        var token = this.getNextToken ();
# Line 228  Line 239 
239            this.setInsertionPoint (oldInsertionPoint);            this.setInsertionPoint (oldInsertionPoint);
240    
241            // 12. If there is a script that will execute as soon as ...            // 12. If there is a script that will execute as soon as ...
242                        while (this.scriptExecutedWhenParserResumes) {
243                // 12.1. If the tree construction stage is being called reentrantly
244                if (this.reentrant) {
245                  log ('parse: abort (reentrance)');
246                  logIndentLevel--;
247                  return;
248    
249                // 12.2. Otherwise
250                } else {
251                  // 1.
252                  var script = this.scriptExecutedWhenParserResumes;
253                  this.scriptExecutedWhenParserResumes = null;
254    
255                  // 2. Pause until the script has completed loading.
256                  //
257    
258                  // 3. Let the insertion point to just before the next input char.
259                  this.setInsertionPoint (0);
260    
261                  // 4. Execute the script.
262                  executeScript (this.doc, script);
263    
264                  // 5. Let the insertion point be undefined again.
265                  this.setInsertionPoint (undefined);
266    
267                  // 6. If there is once again a script that will execute ...
268                  //
269                }
270              }
271          } else {          } else {
272            var el = new JSElement (this.doc, token.value);            var el = new JSElement (this.doc, token.value);
273            this.openElements[this.openElements.length - 1].appendChild (el);            this.openElements[this.openElements.length - 1].appendChild (el);
# Line 249  Line 287 
287          break;          break;
288        } else if (token.type == 'abort') {        } else if (token.type == 'abort') {
289          log ('parse: abort');          log ('parse: abort');
290            logIndentLevel--;
291          return;          return;
292        }        }
293      }      }
# Line 283  Line 322 
322      // "delays tha load event" things has completed:      // "delays tha load event" things has completed:
323      // readyState = 'complete'      // readyState = 'complete'
324      log ('load event fired');      log ('load event fired');
325    
326        logIndentLevel--;
327    } // parse    } // parse
328    
329    Parser.prototype.setInsertionPoint = function (ip) {    Parser.prototype.setInsertionPoint = function (ip) {
# Line 316  Line 357 
357      e.parentNode = this;      e.parentNode = this;
358    
359      if (e.localName == 'script') {      if (e.localName == 'script') {
360          logIndentLevel++;
361        log ('Running a script: start');        log ('Running a script: start');
362    
363        var doc = this.ownerDocument || this;        var doc = this.ownerDocument || this;
# Line 334  Line 376 
376        if (e.manakaiAlreadyExecuted) {        if (e.manakaiAlreadyExecuted) {
377          // 2.5. Abort these steps at this point.          // 2.5. Abort these steps at this point.
378          log ('Running a script: aborted');          log ('Running a script: aborted');
379            logIndentLevel--;
380          return e;          return e;
381        }        }
382    
# Line 356  Line 399 
399                   /* && list of scripts that will execute asynchronously is not empty */) {                   /* && list of scripts that will execute asynchronously is not empty */) {
400          // TODO          // TODO
401        } else if (e.src != null && e.manakaiParserInserted) {        } else if (e.src != null && e.manakaiParserInserted) {
402          // TODO          if (p.scriptExecutedWhenParserResumes) {
403              log ('Error: There is a script that will execute as soon as the parser resumes.');
404            }
405            p.scriptExecutedWhenParserResumes = e;
406            log ('Running a script: aborted (src)');
407        } else if (e.src != null) {