}
nextChar(3);
builder.append("-->");
ParserDirectiveToken tok = new ParserDirectiveToken(line, col, builder.toString(), getLineNo(), getColumn(), directive, args);
if (peek(1) == '\r') {
if (peek(2) == '\n') {
nextChar(2);
tok.setTrailingSpace("\r\n");
} else {
tok.setTrailingSpace("\r");
nextChar();
}
} else if (peek(1) == '\n') {
tok.setTrailingSpace("\n");
nextChar();
}
return tok;
} else if (peek(1) == '-' && peek(2) == '-') {
nextChar(2);
// Comment block
builder.append("!--");
while (true) {
if (peek(1) == Tokenizer.EOL) {
return new CommentToken(line, col, builder.toString(), getLineNo(), getColumn());
}
if (peek(1) == '-' && peek(2) == '-' && peek(3) == '>') break;
builder.append(nextChar());
}
nextChar(3);
builder.append("-->");
return new CommentToken(line, col, builder.toString(), getLineNo(), getColumn());
// CDATA Blocks
} else if ("[CDATA[".equals(peekString(7))) {
c = nextChar(7);
builder.append("![CDATA");
while (true) {
builder.append(c);
if (peek(1) == Tokenizer.EOL) {
return new CDATAToken(line, col, builder.toString(), getLineNo(), getColumn());
} else {
if (peek(1) == ']' && peek(2) == ']' && peek(3) == '>') {
builder.append("]]>");
break;
}
}
c = nextChar();
}
nextChar(3);
return new CDATAToken(line, col, builder.toString(), getLineNo(), getColumn());
// DOCTYPE DECLARATIONS
} else {
while (c != '>') {
builder.append(c);
if (peek(1) == Tokenizer.EOL) {
break;
}
c = nextChar();
}
if (c == '>') {
builder.append(c);
}
return new DocTypeToken(line, col, builder.toString(), getLineNo(), getColumn());
}
// TAG CLOSE </X>
} else if (peek(1) == '/') {
builder.append(c);
c = nextChar();
String tagName = null;
while (c != '>') {
builder.append(c);
if (peek(1) == Tokenizer.EOL) {
break;
}
c = nextChar();
if (tagName == null && (Character.isWhitespace(c) || c == '>')) {
tagName = builder.substring(2).toLowerCase();
}
}
if (c == '>') {
builder.append(c);
}
state = State.INITIAL_STATE;
CloseTagToken tok = new CloseTagToken(line, col, builder.toString(), getLineNo(), getColumn());
tok.setTagName(tagName);
return tok;
// OPEN TAG <X
} else if (CharUtil.isLetter((int) peek(1))) {
c = nextChar();