本文整理匯總了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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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;
}
示例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;
}