当前位置: 首页>>代码示例>>Java>>正文


Java BufferedTokenStream类代码示例

本文整理汇总了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;
	}
 
开发者ID:curiosag,项目名称:ftc,代码行数:19,代码来源:QueryHandler.java

示例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();
    }
}
 
开发者ID:openEHR,项目名称:adl2-core,代码行数:20,代码来源:AdlDeserializer.java

示例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);
}
 
开发者ID:mini2Dx,项目名称:jarn,代码行数:9,代码来源:YarnTreeParser.java

示例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);
}
 
开发者ID:mini2Dx,项目名称:jarn,代码行数:12,代码来源:YarnParserTest.java

示例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;
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:31,代码来源:ParserSupport.java

示例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);
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:10,代码来源:NameToIDSubstitution.java

示例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));
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:8,代码来源:CursorContextListener.java

示例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();
}
 
开发者ID:Consoar,项目名称:Objc2Lua,代码行数:9,代码来源:ParserObjcListener.java

示例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();
}
 
开发者ID:pvoosten,项目名称:JavaSharp,代码行数:11,代码来源:SyntaxTreeXmlFilter.java

示例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;
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:55,代码来源:PathMatcher.java

示例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;
}
 
开发者ID:groupon,项目名称:monsoon,代码行数:57,代码来源:TimeSeriesMetricExpression.java

示例12: SyntaxElementListener

import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public SyntaxElementListener(FusionTablesSqlParser parser, BufferedTokenStream tokens)
{
	super(tokens);
	this.parser = parser;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:6,代码来源:SyntaxElementListener.java

示例13: BaseFtListener

import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
public BaseFtListener(BufferedTokenStream tokens) {
	this.tokens = tokens;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:4,代码来源:BaseFtListener.java

示例14: ServiceParseListener

import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
protected ServiceParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
}
 
开发者ID:protostuff,项目名称:protostuff-compiler,代码行数:4,代码来源:ServiceParseListener.java

示例15: ProtoParseListener

import org.antlr.v4.runtime.BufferedTokenStream; //导入依赖的package包/类
ProtoParseListener(BufferedTokenStream tokens, ProtoContext context) {
    super(tokens, context);
    this.tokens = tokens;
}
 
开发者ID:protostuff,项目名称:protostuff-compiler,代码行数:5,代码来源:ProtoParseListener.java


注:本文中的org.antlr.v4.runtime.BufferedTokenStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。