• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3var Parser = require('../tree_construction/parser'),
4    ParsingUnit = require('./parsing_unit');
5
6//API
7exports.parseDocument = function (html, treeAdapter) {
8    //NOTE: this should be reentrant, so we create new parser here
9    var parser = new Parser(treeAdapter),
10        parsingUnit = new ParsingUnit(parser);
11
12    //NOTE: override parser loop method
13    parser._runParsingLoop = function () {
14        parsingUnit.parsingLoopLock = true;
15
16        while (!parsingUnit.suspended && !this.stopped)
17            this._iterateParsingLoop();
18
19        parsingUnit.parsingLoopLock = false;
20
21        if (this.stopped)
22            parsingUnit.callback(this.document);
23    };
24
25    //NOTE: wait while parserController will be adopted by calling code, then
26    //start parsing
27    process.nextTick(function () {
28        parser.parse(html);
29    });
30
31    return parsingUnit;
32};
33
34exports.parseInnerHtml = function (innerHtml, contextElement, treeAdapter) {
35    //NOTE: this should be reentrant, so we create new parser here
36    var parser = new Parser(treeAdapter);
37
38    return parser.parseFragment(innerHtml, contextElement);
39};