本文整理了Java中org.antlr.v4.runtime.Token.getInputStream()
方法的一些代码示例,展示了Token.getInputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Token.getInputStream()
方法的具体详情如下:
包路径:org.antlr.v4.runtime.Token
类名称:Token
方法名:getInputStream
[英]Gets the CharStream from which this token was derived.
[中]获取从中派生此令牌的字符流。
代码示例来源:origin: apache/hive
/**
* Append the text preserving the formatting (space symbols) between tokens
*/
void append(StringBuilder str, String appendStr, Token start, Token stop) {
String spaces = start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getStartIndex(), stop.getStopIndex()));
spaces = spaces.substring(start.getText().length(), spaces.length() - stop.getText().length());
str.append(spaces);
str.append(appendStr);
}
代码示例来源:origin: apache/hive
/**
* Get formatted text between 2 tokens
*/
public String getFormattedText(ParserRuleContext ctx) {
return ctx.start.getInputStream().getText(
new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
}
代码示例来源:origin: apache/hive
/**
* Get node text including spaces
*/
String getText(ParserRuleContext ctx) {
return ctx.start.getInputStream().getText(new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
}
代码示例来源:origin: apache/hive
/**
* Get node text including spaces
*/
String getText(ParserRuleContext ctx) {
return ctx.start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex()));
}
代码示例来源:origin: confluentinc/ksql
private static String getStatementString(
final SingleStatementContext singleStatementContext
) {
final CharStream charStream = singleStatementContext.start.getInputStream();
return charStream.getText(Interval.of(
singleStatementContext.start.getStartIndex(),
singleStatementContext.stop.getStopIndex()
));
}
}
代码示例来源:origin: apache/hive
String getText(ParserRuleContext ctx, Token start, Token stop) {
return ctx.start.getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getStartIndex(), stop.getStopIndex()));
}
代码示例来源:origin: debezium/debezium
/**
* Returns matched part of the getText for the context.
*
* @param ctx the parser rule context; may not be null
* @return matched part of the getText
*/
public static String getText(ParserRuleContext ctx) {
Interval interval = new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
return ctx.start.getInputStream().getText(interval);
}
代码示例来源:origin: apache/hive
void append(StringBuilder str, TerminalNode start, TerminalNode stop) {
String text = start.getSymbol().getInputStream().getText(new org.antlr.v4.runtime.misc.Interval(start.getSymbol().getStartIndex(), stop.getSymbol().getStopIndex()));
str.append(text);
}
代码示例来源:origin: apache/hive
/**
* Executing OS command
*/
@Override
public Integer visitHost_cmd(HplsqlParser.Host_cmdContext ctx) {
trace(ctx, "HOST");
execHost(ctx, ctx.start.getInputStream().getText(
new org.antlr.v4.runtime.misc.Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex())));
return 0;
}
代码示例来源:origin: prestodb/presto
@Override
public void exitNonReserved(SqlBaseParser.NonReservedContext context)
{
// we can't modify the tree during rule enter/exit event handling unless we're dealing with a terminal.
// Otherwise, ANTLR gets confused an fires spurious notifications.
if (!(context.getChild(0) instanceof TerminalNode)) {
int rule = ((ParserRuleContext) context.getChild(0)).getRuleIndex();
throw new AssertionError("nonReserved can only contain tokens. Found nested rule: " + ruleNames.get(rule));
}
// replace nonReserved words with IDENT tokens
context.getParent().removeLastChild();
Token token = (Token) context.getChild(0).getPayload();
context.getParent().addChild(new CommonToken(
new Pair<>(token.getTokenSource(), token.getInputStream()),
SqlBaseLexer.IDENTIFIER,
token.getChannel(),
token.getStartIndex(),
token.getStopIndex()));
}
}
代码示例来源:origin: debezium/debezium
@Override
public void enterDropTable(MySqlParser.DropTableContext ctx) {
Interval interval = new Interval(ctx.start.getStartIndex(), ctx.tables().start.getStartIndex() - 1);
String prefix = ctx.start.getInputStream().getText(interval);
ctx.tables().tableName().forEach(tableNameContext -> {
TableId tableId = parser.parseQualifiedTableId(tableNameContext.fullId());
parser.databaseTables().removeTable(tableId);
parser.signalDropTable(tableId, prefix + tableId.table()
+ (ctx.dropType != null ? " " + ctx.dropType.getText() : ""));
});
super.enterDropTable(ctx);
}
}
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* {@inheritDoc}
*/
@Override
public CharStream getInputStream() {
if (i < tokens.size()) {
return tokens.get(i).getInputStream();
}
else if (eofToken != null) {
return eofToken.getInputStream();
}
else if (tokens.size() > 0) {
return tokens.get(tokens.size() - 1).getInputStream();
}
// no input stream information is available
return null;
}
代码示例来源:origin: org.antlr/antlr4-runtime
/**
* Constructs a new {@link CommonToken} as a copy of another {@link Token}.
*
* <p>
* If {@code oldToken} is also a {@link CommonToken} instance, the newly
* constructed token will share a reference to the {@link #text} field and
* the {@link Pair} stored in {@link #source}. Otherwise, {@link #text} will
* be assigned the result of calling {@link #getText}, and {@link #source}
* will be constructed from the result of {@link Token#getTokenSource} and
* {@link Token#getInputStream}.</p>
*
* @param oldToken The token to copy.
*/
public CommonToken(Token oldToken) {
type = oldToken.getType();
line = oldToken.getLine();
index = oldToken.getTokenIndex();
charPositionInLine = oldToken.getCharPositionInLine();
channel = oldToken.getChannel();
start = oldToken.getStartIndex();
stop = oldToken.getStopIndex();
if (oldToken instanceof CommonToken) {
text = ((CommonToken)oldToken).text;
source = ((CommonToken)oldToken).source;
}
else {
text = oldToken.getText();
source = new Pair<TokenSource, CharStream>(oldToken.getTokenSource(), oldToken.getInputStream());
}
}
代码示例来源:origin: korpling/ANNIS
@Override
public CharStream getInputStream()
{
if(token.isEmpty())
{
return eofToken.getInputStream();
}
else
{
return token.get(0).getInputStream();
}
}
代码示例来源:origin: korpling/ANNIS
@Override
public String getSourceName()
{
if(token.isEmpty())
{
return eofToken.getInputStream().getSourceName();
}
else
{
return token.get(0).getInputStream().getSourceName();
}
}
代码示例来源:origin: io.debezium/debezium-ddl-parser
/**
* Returns matched part of the getText for the context.
*
* @param ctx the parser rule context; may not be null
* @return matched part of the getText
*/
public static String getText(ParserRuleContext ctx) {
Interval interval = new Interval(ctx.start.getStartIndex(), ctx.stop.getStopIndex());
return ctx.start.getInputStream().getText(interval);
}
代码示例来源:origin: org.kie/kie-dmn-feel
public static String getOriginalText(ParserRuleContext ctx) {
int a = ctx.start.getStartIndex();
int b = ctx.stop.getStopIndex();
Interval interval = new Interval( a, b );
return ctx.getStart().getInputStream().getText( interval );
}
代码示例来源:origin: nielsbasjes/yauaa
public static String getSourceText(ParserRuleContext ctx){
if (ctx.start == null || ctx.stop == null) {
return ctx.getText();
}
int startIndex = ctx.start.getStartIndex();
int stopIndex = ctx.stop.getStopIndex();
if (stopIndex < startIndex) {
return ""; // Just return the empty string.
}
CharStream inputStream = ctx.start.getInputStream();
return inputStream.getText(new Interval(startIndex, stopIndex));
}
代码示例来源:origin: org.kie/kie-dmn-feel
private String getOriginalText( ParserRuleContext ctx ) {
int a = ctx.start.getStartIndex();
int b = ctx.stop.getStopIndex();
Interval interval = new Interval(a,b);
return ctx.getStart().getInputStream().getText(interval);
}
代码示例来源:origin: org.bitbucket.goalhub.grammar/languageTools
private String getText(ParserRuleContext ctx) {
int start = ctx.start.getStartIndex();
int stop = (ctx.stop == null) ? start : ctx.stop.getStopIndex();
return ctx.getStart().getInputStream().getText(new Interval(start, stop));
}
}
内容来源于网络,如有侵权,请联系作者删除!