本文整理汇总了Java中org.antlr.v4.runtime.CharStream.seek方法的典型用法代码示例。如果您正苦于以下问题:Java CharStream.seek方法的具体用法?Java CharStream.seek怎么用?Java CharStream.seek使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.antlr.v4.runtime.CharStream
的用法示例。
在下文中一共展示了CharStream.seek方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBytes
import org.antlr.v4.runtime.CharStream; //导入方法依赖的package包/类
private static byte[] getBytes(Literal_value_binaryContext rule) {
Token token = rule.STRING_LITERAL().getSymbol();
byte[] bytes = new byte[token.getStopIndex() - token.getStartIndex() - 1];
CharStream cs = token.getInputStream();
int pos = cs.index();
cs.seek(token.getStartIndex() + 1);
int j = 0;
for (int i = 0; i < bytes.length; i++) {
int ch = cs.LA(i + 1);
if (ch == '\\') {
i++;
ch = cs.LA(i + 1);
if (ch == '0') {
ch = 0;
}
else if (ch == 'n') {
ch = '\n';
}
else if (ch == 'r') {
ch = '\r';
}
else if (ch == 'Z') {
ch = '\032';
}
}
bytes[j] = (byte) ch;
j++;
}
cs.seek(pos);
if (j != bytes.length) {
// esacpe characters
byte[] old = bytes;
bytes = new byte[j];
System.arraycopy(old, 0, bytes, 0, j);
}
return bytes;
}
示例2: resetAcceptPosition
import org.antlr.v4.runtime.CharStream; //导入方法依赖的package包/类
protected void resetAcceptPosition(CharStream input, int index, int line, int charPositionInLine) {
input.seek(index);
this.line = line;
this.charPositionInLine = charPositionInLine;
consume(input);
}