本文整理汇总了Java中jdk.nashorn.internal.parser.TokenStream.get方法的典型用法代码示例。如果您正苦于以下问题:Java TokenStream.get方法的具体用法?Java TokenStream.get怎么用?Java TokenStream.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jdk.nashorn.internal.parser.TokenStream
的用法示例。
在下文中一共展示了TokenStream.get方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: dumpTokens
import jdk.nashorn.internal.parser.TokenStream; //导入方法依赖的package包/类
/**
* Dump a token stream to stdout
*
* TODO: most other bugging goes to stderr, change?
*
* @param source the source
* @param lexer the lexer
* @param stream the stream to dump
*/
public static void dumpTokens(final Source source, final Lexer lexer, final TokenStream stream) {
TokenType type;
int k = 0;
do {
while (k > stream.last()) {
// Get more tokens.
lexer.lexify();
}
final long token = stream.get(k);
type = Token.descType(token);
System.out.println("" + k + ": " + Token.toString(source, token, true));
k++;
} while(type != EOF);
}
示例2: getCommentsTokens
import jdk.nashorn.internal.parser.TokenStream; //导入方法依赖的package包/类
/**
* Extracts the comments tokens from a JavaScript source.
*
* @param aSource a source
* @return a list of comment tokens
*/
public static List<Long> getCommentsTokens(String aSource) {
TokenStream tokens = new TokenStream();
Lexer lexer = new Lexer(Source.sourceFor("", aSource), tokens);//NOI18N
long t;
TokenType tt = TokenType.EOL;
int i = 0;
List<Long> commentsTokens = new ArrayList<>();
while (tt != TokenType.EOF) {
// Get next token in nashorn's parser way
while (i > tokens.last()) {
if (tokens.isFull()) {
tokens.grow();
}
lexer.lexify();
}
t = tokens.get(i++);
tt = Token.descType(t);
if (tt == TokenType.COMMENT) {
commentsTokens.add(t);
}
}
return commentsTokens;
}