diff --git a/htmlparser/gwt2/build.sh b/htmlparser/gwt2/build.sh index dddf8846..f17e45fc 100755 --- a/htmlparser/gwt2/build.sh +++ b/htmlparser/gwt2/build.sh @@ -3,19 +3,22 @@ # # Autodownload Parser # from mozilla HG. -# TODO: specific specific releases +# TODO: use specific releases # PARSER=htmlparser # # Use mozilla trunk # +echo "HG update from http://hg.mozilla.org/projects/htmlparser" if [ ! -d "${PARSER}" ]; then hg clone http://hg.mozilla.org/projects/htmlparser else (cd "${PARSER}"; hg pull; hg update ) fi +echo "----" +echo "Installing GWT" # # Autodownload GWT @@ -28,15 +31,17 @@ if [ ! -d "${GWT}" ]; then wget "http://google-web-toolkit.googlecode.com/files/${GWT_ZIP}" unzip ${GWT_ZIP} fi +echo "----" -echo "Starting GWT compile..." CP="./src:./${PARSER}/src:./${PARSER}/super:./${GWT}/gwt-user.jar:./${GWT}/gwt-dev.jar" # Compile a new GWT linker. Very simple to Single Script Linker but # removes all the "bootstrap" and client (real browser) onScriptLoad # events, etc. +echo "Javac our linker" javac -cp ${CP} src/com/envjs/gwt/linker/ServerSingleScriptLinker.java +echo "Starting GWT..." java \ -Xmx256M \ -cp "${CP}" \ @@ -46,7 +51,7 @@ java \ nu.validator.htmlparser.HtmlParser; # -draftCompile \ - +echo "----" echo "COPY to envjs src tree" cp war/nu.validator.htmlparser.HtmlParser/nu.validator.htmlparser.HtmlParser.nocache.js ../../src/parser/htmlparser.js diff --git a/htmlparser/gwt2/src/nu/validator/htmlparser/gwt/HtmlParser.java b/htmlparser/gwt2/src/nu/validator/htmlparser/gwt/HtmlParser.java index 510cc75d..eab4a9eb 100644 --- a/htmlparser/gwt2/src/nu/validator/htmlparser/gwt/HtmlParser.java +++ b/htmlparser/gwt2/src/nu/validator/htmlparser/gwt/HtmlParser.java @@ -144,16 +144,73 @@ private void tokenize(String source, final boolean useSetTimeouts, String contex pump(useSetTimeouts); } + /** + * pump pushes tokens out to the parser (I believe). + * + * The default version of this (same file/directory but in the + * htmlparser/src-gwt directory, works file. However this has + * been hacked for the "useSetTimeout" flag which corresponses to + * the doc.async flag (with async --> use SetTimeouts). + * + * The async version parses a token then calls SetTimeout with 1ms, + * to be called again inorder to get another token. This lets other + * tasks in the timer run (perhaps networking) or pre-empty the parser. + * + * The Sync version just repeatably calls pumpcore + */ private void pump(boolean useSetTimeouts) throws SAXException { - + if (pumpcore()) { + return; + } + + if(useSetTimeouts){ + // schedule + Timer timer = new Timer() { + + @Override public void run() { + try { + pump(true); + } catch (SAXException e) { + ending = true; + if (errorHandler != null) { + try { + errorHandler.fatalError(new SAXParseException( + e.getMessage(), null, null, -1, -1, e)); + } catch (SAXException e1) { + } + } + } + } + + }; + timer.schedule(1); + }else{ + try { + while (!pumpcore()) { } + } catch (SAXException e) { + ending = true; + if (errorHandler != null) { + try { + errorHandler.fatalError(new SAXParseException( + e.getMessage(), null, null, -1, -1, e)); + } catch (SAXException e1) { + } + } + } + } + } + + private boolean pumpcore() throws SAXException { + if (ending) { tokenizer.end(); domTreeBuilder.getDocument(); // drops the internal reference parseEndListener.parseComplete(); // Don't schedule timeout - return; - } + return true; + } + int docWriteLen = documentWriteBuffer.length(); if (docWriteLen > 0) { @@ -194,42 +251,8 @@ private void pump(boolean useSetTimeouts) throws SAXException { continue; } } + return false; - if(useSetTimeouts){ - // schedule - Timer timer = new Timer() { - - @Override public void run() { - try { - pump(true); - } catch (SAXException e) { - ending = true; - if (errorHandler != null) { - try { - errorHandler.fatalError(new SAXParseException( - e.getMessage(), null, null, -1, -1, e)); - } catch (SAXException e1) { - } - } - } - } - - }; - timer.schedule(1); - }else{ - try { - pump(false); - } catch (SAXException e) { - ending = true; - if (errorHandler != null) { - try { - errorHandler.fatalError(new SAXParseException( - e.getMessage(), null, null, -1, -1, e)); - } catch (SAXException e1) { - } - } - } - } } private void push(UTF16Buffer buffer) {