// parseJavaScript in parsejavascript.js (there is actually a bit more
// shared code than I'd like), but it is quite a bit simpler.
function parseXML(source) {
- var tokens = tokenizeXML(source);
+ var tokens = tokenizeXML(source), token;
var cc = [base];
var tokenNr = 0, indented = 0;
var currentTag = null, context = null;
- var consume, marked;
-
+ var consume;
+
function push(fs) {
for (var i = fs.length - 1; i >= 0; i--)
cc.push(fs[i]);
consume = false;
}
- function mark(style) {
- marked = style;
+ function markErr() {
+ token.style += " xml-error";
}
function expect(text) {
return function(style, content) {
if (content == text) cont();
- else mark("xml-error") || cont(arguments.callee);
+ else {markErr(); cont(arguments.callee);}
};
}
cont();
}
else if (harmlessTokens.hasOwnProperty(style)) cont();
- else mark("xml-error") || cont();
+ else {markErr(); cont();}
}
function tagname(style, content) {
if (style == "xml-name") {
currentTag = content.toLowerCase();
- mark("xml-tagname");
+ token.style = "xml-tagname";
cont();
}
else {
}
}
function closetagname(style, content) {
- if (style == "xml-name" && context && content.toLowerCase() == context.name) {
- popContext();
- mark("xml-tagname");
- }
- else {
- mark("xml-error");
+ if (style == "xml-name") {
+ token.style = "xml-tagname";
+ if (context && content.toLowerCase() == context.name) popContext();
+ else markErr();
}
cont();
}
function endtag(startOfLine) {
return function(style, content) {
if (content == "/>" || (content == ">" && UseKludges.autoSelfClosers.hasOwnProperty(currentTag))) cont();
- else if (content == ">") pushContext(currentTag, startOfLine) || cont();
- else mark("xml-error") || cont(arguments.callee);
+ else if (content == ">") {pushContext(currentTag, startOfLine); cont();}
+ else {markErr(); cont(arguments.callee);}
};
}
function attributes(style) {
- if (style == "xml-name") mark("xml-attname") || cont(attribute, attributes);
+ if (style == "xml-name") {token.style = "xml-attname"; cont(attribute, attributes);}
else pass();
}
function attribute(style, content) {
indentation: function() {return indented;},
next: function(){
- var token = tokens.next();
+ token = tokens.next();
if (token.style == "whitespace" && tokenNr == 0)
indented = token.value.length;
else
return token;
while(true){
- consume = marked = false;
+ consume = false;
cc.pop()(token.style, token.content);
- if (consume){
- if (marked)
- token.style = marked;
- return token;
- }
+ if (consume) return token;
}
},
copy: function(){
var _cc = cc.concat([]), _tokenState = tokens.state, _context = context;
var parser = this;
-
+
return function(input){
cc = _cc.concat([]);
tokenNr = indented = 0;