State s = parseRegExp() ;
if (currChar != '/') {
throw new InvalidRegExp(getPosition()) ;
}
readChar() ;
return new Token("REGEXP",s) ;
}
if (cc == '{') {
String code = parseCode() ;
return new Token("CODE",code) ;
}
if (cc == '%') {
readChar() ;
StringBuilder sb = new StringBuilder() ;
while(currChar >= 0 && Character.isJavaIdentifierPart((char)currChar)) {
sb.append((char)currChar) ;
readChar() ;
}
String dir = sb.toString() ;
if (dir.equals("extends")) {
return new Token("EXTENDS") ;
}
else if (dir.equals("import")) {
return new Token("IMPORT") ;
}
else {
throw new InvalidDirective(getPosition(),dir) ;
}
}
if (Character.isJavaIdentifierStart(cc)) {
StringBuilder sb = new StringBuilder() ;
while(currChar >= 0 && Character.isJavaIdentifierPart((char)currChar)) {
sb.append((char)currChar) ;
readChar() ;
}
return new Token("ID",sb.toString()) ;
}
readChar() ;
return new Token(String.valueOf(cc)) ;
}
}