當前位置: 首頁>>代碼示例>>Java>>正文


Java CharStreams.fromReader方法代碼示例

本文整理匯總了Java中org.antlr.v4.runtime.CharStreams.fromReader方法的典型用法代碼示例。如果您正苦於以下問題:Java CharStreams.fromReader方法的具體用法?Java CharStreams.fromReader怎麽用?Java CharStreams.fromReader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.antlr.v4.runtime.CharStreams的用法示例。


在下文中一共展示了CharStreams.fromReader方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: compile

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static Matcher compile(String query) {
  try {
    CodePointCharStream input = CharStreams.fromReader(new StringReader(query));
    ExprLexer lexer = new ExprLexer(input);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    ExprParser parser = new ExprParser(tokens);
    ParseTree tree = parser.expr();
    Visitor visitor = new Visitor();
    visitor.visit(tree);
    return visitor.expression().normalize();
  } catch (IOException e) {
    throw new RuntimeException(e.getLocalizedMessage(), e);
  }
}
 
開發者ID:before,項目名稱:simple-text-search-library,代碼行數:15,代碼來源:Pattern.java

示例2: configuration

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的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

示例3: createCharStream

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
private CharStream createCharStream(SourceUnit sourceUnit) {
    CharStream charStream;

    try {
        charStream = CharStreams.fromReader(
                new BufferedReader(sourceUnit.getSource().getReader()),
                sourceUnit.getName());
    } catch (IOException e) {
        throw new RuntimeException("Error occurred when reading source code.", e);
    }

    return charStream;
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:14,代碼來源:AstBuilder.java

示例4: compile

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public CompiledScript compile(Reader script) throws ScriptException {
    try {
        CharStream input = CharStreams.fromReader(script);
        BabbleLexer lexer = new BabbleLexer(input);
        CommonTokenStream tokenStream = new CommonTokenStream(lexer);
        BabbleParser parser = new BabbleParser(tokenStream);
        parser.setErrorHandler(new BailErrorStrategy());
        BabbleParser.FileContext file = parser.file();
        return compile(file);
    } catch (Exception e) {
        throw new ScriptException(e);
    }
}
 
開發者ID:nlehuen,項目名稱:babble,代碼行數:14,代碼來源:BabbleScriptEngine.java

示例5: valueOf

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的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

示例6: valueOf

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的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


注:本文中的org.antlr.v4.runtime.CharStreams.fromReader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。