本文整理汇总了Java中org.antlr.v4.runtime.BufferedTokenStream类的典型用法代码示例。如果您正苦于以下问题:Java BufferedTokenStream类的具体用法?Java BufferedTokenStream怎么用?Java BufferedTokenStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BufferedTokenStream类属于org.antlr.v4.runtime包,在下文中一共展示了BufferedTokenStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addNonSyntaxTokens
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
private List<SyntaxElement> addNonSyntaxTokens(List<SyntaxElement> syntaxElements, BufferedTokenStream tokens) {
StackLight<SyntaxElement> regularElements = new StackLight<SyntaxElement>(syntaxElements);
List<SyntaxElement> result = new LinkedList<SyntaxElement>();
for (Token t : tokens.getTokens()) {
if (!regularElements.empty() && regularElements.peek().tokenIndex == t.getTokenIndex())
result.add(regularElements.pop());
else {
SyntaxElementType type = getIrregularType(t);
if (type != SyntaxElementType.unknown)
result.add(SyntaxElement.create(t, type));
}
}
return result;
}
示例2: parse
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public Archetype parse(Reader reader) throws IOException {
try {
CharStream charStream = new ANTLRInputStream(reader);
Lexer lexer = new adlLexer(charStream);
adlParser parser = new adlParser(new BufferedTokenStream(lexer));
AccumulatingErrorListener errorHandler = new AccumulatingErrorListener();
parser.removeErrorListeners();
parser.addErrorListener(errorHandler);
adlParser.AdlContext context = parser.adl();
if (!errorHandler.getErrors().isEmpty()) {
throw new AdlParserException(Joiner.on("\n").join(errorHandler.getErrors()));
}
AdlTreeParser treeParser = new AdlTreeParser();
return treeParser.parseAdl(context);
} finally {
reader.close();
}
}
示例3: parseNodeContent
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
private void parseNodeContent(String nodeContent) throws IOException {
YarnLexer yarnLexer = new YarnLexer(new ANTLRInputStream(nodeContent));
YarnParser yarnParser = new YarnParser(new BufferedTokenStream(yarnLexer));
NodeContext nodeContext = yarnParser.node();
ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
parseTreeWalker.walk(this, nodeContext);
}
示例4: runTest
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
private void runTest(String filename) throws Exception {
System.out.println("------------- " + filename + " -------------");
YarnLexer yarnLexer = new YarnLexer(new ANTLRInputStream(YarnParserTest.class.getResourceAsStream("/" + filename)));
YarnParser yarnParser = new YarnParser(new BufferedTokenStream(yarnLexer));
yarnParser.setTrace(true);
NodeContext nodeContext = yarnParser.node();
ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
parseTreeWalker.walk(this, nodeContext);
}
示例5: configuration
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public Configuration configuration() throws IOException, ConfigurationException {
final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();
final ConfigTokenizer lexer = new ConfigTokenizer(CharStreams.fromReader(reader_));
lexer.removeErrorListeners();
lexer.addErrorListener(error_listener);
final ConfigParser parser = new ConfigParser(new BufferedTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(error_listener);
dir_.ifPresent(parser::setDir);
final ConfigParser.ExprContext expr;
try {
expr = parser.expr();
} catch (Exception ex) {
LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
if (!error_listener.errors.isEmpty())
throw new ConfigurationException(error_listener.errors, ex);
else
throw ex;
}
if (!error_listener.errors.isEmpty()) {
if (expr.exception != null)
throw new ConfigurationException(error_listener.errors, expr.exception);
throw new ConfigurationException(error_listener.errors);
} else if (expr.exception != null) {
throw new ConfigurationException(expr.exception);
}
return expr.s;
}
示例6: NameToIDSubstitution
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public NameToIDSubstitution(FusionTablesSqlParser parser, BufferedTokenStream tokens,
TableNameToIdMapper namesToIds, Map<String, String> tableAliasToName) {
Check.notNull(tokens);
Check.notNull(namesToIds);
Check.notNull(tableAliasToName);
this.mapper = namesToIds;
rewriter = new TokenStreamRewriter(tokens);
}
示例7: CursorContextListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public CursorContextListener(int cursorIndex, FusionTablesSqlParser parser, BufferedTokenStream tokens) {
super(parser, tokens);
this.cursorIndex = cursorIndex;
this.parser = parser;
printDebug(String.format("\ngetting context at position %d", cursorIndex));
}
示例8: ParserObjcListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
ParserObjcListener(ClassDescription classDescription,
BufferedTokenStream tokens, ParseOptions options) {
super();
this.classDescription = classDescription;
this.options = options;
this.tokens = tokens;
this.classDeclarations = classDescription.getmFiles();
}
示例9: parse
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
@Override
public void parse(String javaSourcePath) throws SAXException, IOException {
// parse the Java file(s) with the ANTLR generated parser
JavaParser.CompilationUnitContext ctx = readSourceFile(javaSourcePath);
// visit the AST with the XmlEmittingVisitor, which generates SAX events
startDocument();
XmlEmittingVisitor visitor = new XmlEmittingVisitor(this, (BufferedTokenStream) parser.getTokenStream());
visitor.visit(ctx);
endDocument();
}
示例10: valueOf
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
/**
* Read path matcher from reader.
*
* @param reader A reader supplying the input of a path expression.
* @return A PathMatcher corresponding to the parsed input
* from the reader.
* @throws IOException on IO errors from the reader.
* @throws
* com.groupon.lex.metrics.PathMatcher.ParseException
* on invalid path expression.
*/
public static PathMatcher valueOf(Reader reader) throws IOException, ParseException {
class DescriptiveErrorListener extends BaseErrorListener {
public List<String> errors = new ArrayList<>();
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, org.antlr.v4.runtime.RecognitionException e) {
LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg});
errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg));
}
}
final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();
final PathMatcherLexer lexer = new PathMatcherLexer(CharStreams.fromReader(reader));
lexer.removeErrorListeners();
lexer.addErrorListener(error_listener);
final PathMatcherGrammar parser = new PathMatcherGrammar(new BufferedTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(error_listener);
final PathMatcherGrammar.ExprContext expr;
try {
expr = parser.expr();
} catch (Exception ex) {
LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
if (!error_listener.errors.isEmpty())
throw new ParseException(error_listener.errors, ex);
else
throw ex;
}
if (!error_listener.errors.isEmpty()) {
if (expr.exception != null)
throw new ParseException(error_listener.errors, expr.exception);
throw new ParseException(error_listener.errors);
} else if (expr.exception != null) {
throw new ParseException(expr.exception);
}
return expr.s;
}
示例11: valueOf
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
/**
* Read expression from reader.
*
* @param reader A reader supplying the input of an expression.
* @return A TimeSeriesMetricExpression corresponding to the parsed input
* from the reader.
* @throws IOException on IO errors from the reader.
* @throws
* com.groupon.lex.metrics.timeseries.TimeSeriesMetricExpression.ParseException
* on invalid expression.
*/
public static TimeSeriesMetricExpression valueOf(Reader reader) throws IOException, ParseException {
final Logger LOG = Logger.getLogger(TimeSeriesMetricExpression.class.getName());
class DescriptiveErrorListener extends BaseErrorListener {
public List<String> errors = new ArrayList<>();
@Override
public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol,
int line, int charPositionInLine,
String msg, org.antlr.v4.runtime.RecognitionException e) {
LOG.log(Level.INFO, "Parse error: {0}:{1} -> {2}", new Object[]{line, charPositionInLine, msg});
errors.add(String.format("%d:%d: %s", line, charPositionInLine, msg));
}
}
final DescriptiveErrorListener error_listener = new DescriptiveErrorListener();
final ExpressionLexer lexer = new ExpressionLexer(CharStreams.fromReader(reader));
lexer.removeErrorListeners();
lexer.addErrorListener(error_listener);
final Expression parser = new Expression(new BufferedTokenStream(lexer));
parser.removeErrorListeners();
parser.addErrorListener(error_listener);
final Expression.ExprContext expr;
try {
expr = parser.expr();
} catch (Exception ex) {
LOG.log(Level.SEVERE, "parser yielded exceptional return", ex);
if (!error_listener.errors.isEmpty())
throw new ParseException(error_listener.errors, ex);
else
throw ex;
}
if (!error_listener.errors.isEmpty()) {
if (expr.exception != null)
throw new ParseException(error_listener.errors, expr.exception);
throw new ParseException(error_listener.errors);
} else if (expr.exception != null) {
throw new ParseException(expr.exception);
}
return expr.s;
}
示例12: SyntaxElementListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public SyntaxElementListener(FusionTablesSqlParser parser, BufferedTokenStream tokens)
{
super(tokens);
this.parser = parser;
}
示例13: BaseFtListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public BaseFtListener(BufferedTokenStream tokens) {
this.tokens = tokens;
}
示例14: ServiceParseListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
protected ServiceParseListener(BufferedTokenStream tokens, ProtoContext context) {
super(tokens, context);
}
示例15: ProtoParseListener
import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
ProtoParseListener(BufferedTokenStream tokens, ProtoContext context) {
super(tokens, context);
this.tokens = tokens;
}