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


Java CharStream类代码示例

本文整理汇总了Java中org.antlr.v4.runtime.CharStream的典型用法代码示例。如果您正苦于以下问题:Java CharStream类的具体用法?Java CharStream怎么用?Java CharStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CharStream类属于org.antlr.v4.runtime包,在下文中一共展示了CharStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
/**
 * @throws InvalidQueryException if the given query contains invalid characters or is incomplete
 */
public SqlGrammarParser.SelectStatementContext parse(String query) {
    log.trace("About to parse [{}]", query);
    long now = currentTimeMillis();

    CharStream input = CharStreams.fromString(query);
    SqlGrammarLexer lexer = new SqlGrammarLexer(input);
    TokenStream tokenStream = new CommonTokenStream(lexer);
    SqlGrammarParser parser = new SqlGrammarParser(tokenStream);

    parser.removeErrorListeners();
    parser.addErrorListener(new RaiseExceptionErrorListener());

    SqlGrammarParser.SelectStatementContext result = parser.selectStatement();

    log.trace("Successfully parsed [{}] into [{}] in [{}ms]",
            query, result.toStringTree(parser), currentTimeMillis() - now);

    return result;
}
 
开发者ID:michalwojciechowski,项目名称:coherence-sql,代码行数:23,代码来源:SqlParser.java

示例2: parseString

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
@Override
public SortedMap<Integer, String> parseString(String fieldString) {
    CharStream is = CharStreams.fromString(fieldString);
    DrawGrammarLexer lex = new DrawGrammarLexer(is);
    CommonTokenStream tokens = new CommonTokenStream(lex);
    DrawGrammarParser parser = new DrawGrammarParser(tokens);
    palette = Palette.makeDefaultPalette("DarkSpectrum");
    final SortedMap<Integer, String> resultMap;
    try {
        resultMap = parser.root().map;
    } catch (RecognitionException | NullPointerException | StringIndexOutOfBoundsException | RasterFormatException re) {
        //Something wrong with the parsing do not update.
        return null;
    }
    return resultMap;
}
 
开发者ID:fusiled,项目名称:bitbox,代码行数:17,代码来源:PainterLogic.java

示例3: main

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
/**
 * @param args the command line arguments
 * @throws java.io.IOException
 * @throws java.net.URISyntaxException
 */
public static void main(String[] args) throws IOException, URISyntaxException {
    final String entryPoint;
    final URL res;
    switch (args.length) {
    case 2:
        res = Paths.get(args[0]).toUri().toURL();
        entryPoint = args[1];
        break;
    default:
        System.err.println("Supply two parameters in the following order:\n- file name of the main function\n- name of the main function\n\nFor example: hello.ct main:argc:argv");
        return;
    }
    final CharStream inp = CharStreams.fromStream(res.openStream());
    final GrammarLexer lex = new GrammarLexer(inp);
    final TokenStream toks = new CommonTokenStream(lex);
    final GrammarParser parser = new GrammarParser(toks);
    System.out.println(new Translator(res.toURI()).generate(parser.program(), entryPoint));
}
 
开发者ID:plankp,项目名称:CTalk,代码行数:24,代码来源:App.java

示例4: nextToken

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
@Override
public Token nextToken() {
    if (stashedNext != null) {
        previous = stashedNext;
        stashedNext = null;
        return previous;
    }
    Token next = super.nextToken();
    if (insertSemicolon(previous, next)) {
        stashedNext = next;
        previous = _factory.create(new Pair<TokenSource, CharStream>(this, _input), PainlessLexer.SEMICOLON, ";",
                Lexer.DEFAULT_TOKEN_CHANNEL, next.getStartIndex(), next.getStopIndex(), next.getLine(), next.getCharPositionInLine());
        return previous;
    } else {
        previous = next;
        return next;
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:19,代码来源:EnhancedPainlessLexer.java

示例5: recover

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
@Override
public void recover(final LexerNoViableAltException lnvae) {
    final CharStream charStream = lnvae.getInputStream();
    final int startIndex = lnvae.getStartIndex();
    final String text = charStream.getText(Interval.of(startIndex, charStream.index()));

    Location location = new Location(sourceName, _tokenStartCharIndex);
    String message = "unexpected character [" + getErrorDisplay(text) + "].";
    char firstChar = text.charAt(0);
    if ((firstChar == '\'' || firstChar == '"') && text.length() - 2 > 0 && text.charAt(text.length() - 2) == '\\') {
        /* Use a simple heuristic to guess if the unrecognized characters were trying to be a string but has a broken escape sequence.
         * If it was add an extra message about valid string escape sequences. */
        message += " The only valid escape sequences in strings starting with [" + firstChar + "] are [\\\\] and [\\"
                + firstChar + "].";
    }
    throw location.createError(new IllegalArgumentException(message, lnvae));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:18,代码来源:EnhancedPainlessLexer.java

示例6: parseInputStream

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
private void parseInputStream(CharStream inputStream, OboParseResultListener listener) {
  final OboLexer l = new OboLexer(inputStream);
  final Antlr4OboParser p = new Antlr4OboParser(new CommonTokenStream(l));

  p.addErrorListener(new BaseErrorListener() {
    @Override
    public void syntaxError(Recognizer<?, ?> recognizer, Object offendingSymbol, int line,
        int charPositionInLine, String msg, RecognitionException e) {
      throw new IllegalStateException("Failed to parse at line " + line + " due to " + msg, e);
    }
  });

  if (debug) {
    p.addErrorListener(new DiagnosticErrorListener());
  }

  p.addParseListener(new OboParserListener(listener));

  p.oboFile();
}
 
开发者ID:Phenomics,项目名称:ontolib,代码行数:21,代码来源:OboParser.java

示例7: parse

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
public EObject parse(final String typeExpression, final Scope scope) {
    final CharStream charStream = CharStreams.fromString(typeExpression);
    final TypeExpressionLexer lexer = new TypeExpressionLexer(charStream);
    final TokenStream tokenStream = new CommonTokenStream(lexer);
    final TypeExpressionParser typeExpressionParser = new TypeExpressionParser(tokenStream);

    lexer.removeErrorListeners();
    typeExpressionParser.removeErrorListeners();

    final ParserErrorCollector errorCollector = new ParserErrorCollector();
    lexer.addErrorListener(errorCollector);
    typeExpressionParser.addErrorListener(errorCollector);

    final TypeExpressionParser.Type_exprContext typeExpr = typeExpressionParser.type_expr();

    final EObject anyType = new TypeExpressionBuilder(scope, ARRAY_TYPE).visit(typeExpr);
    scope.getResource().getErrors().addAll(errorCollector.getErrors());

    return anyType;
}
 
开发者ID:vrapio,项目名称:rest-modeling-framework,代码行数:21,代码来源:TypeExpressionConstructor.java

示例8: newParser

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
public static <L extends Lexer, P extends Parser> P newParser(
    Function<CharStream, L> lexerFactory,
    Function<TokenStream, P> parserFactory,
    String input,
    boolean useBailErrorStrategy,
    boolean removeErrorListeners) {
  CharStream charStream = new ANTLRInputStream(input);
  L lexer = lexerFactory.apply(charStream);
  if (removeErrorListeners) {
    lexer.removeErrorListeners();
  }

  TokenStream tokenStream = new CommonTokenStream(lexer);
  P parser = parserFactory.apply(tokenStream);
  if (useBailErrorStrategy) {
    parser.setErrorHandler(new BailErrorStrategy());
  }
  if (removeErrorListeners) {
    parser.removeErrorListeners();
  }

  return parser;
}
 
开发者ID:nkouevda,项目名称:antlr-examples,代码行数:24,代码来源:ParserUtil.java

示例9: parse

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
/**
 * Parse an interval, for example <tt>[1,-]</tt> or <tt>-</tt> (a wildcard) or <tt>[1,4]</tt>.
 * Only fixed values are allowed, no variables.
 *
 * @param intervalAsString the string to be parsed.
 * @return a LowerBoundedInterval as the runtime representation of interval strings.
 * @throws ParseException in case the string doesn't fit the given fixed-interval grammar.
 */
public static LowerBoundedInterval parse(String intervalAsString) throws ParseException {
  CharStream charStream = new ANTLRInputStream(intervalAsString);
  CellExpressionLexer lexer = new CellExpressionLexer(charStream);
  TokenStream tokens = new CommonTokenStream(lexer);
  CellExpressionParser parser = new CellExpressionParser(tokens);
  parser.removeErrorListeners();
  parser.addErrorListener(new ThrowingErrorListener());
  try {
    CellExpressionParser.Fixed_intervalContext ctx = parser.fixed_interval();
    if (ctx == null) {
      throw new ParseException(0, 0, "Expected fixed interval");
    }
    return INSTANCE.visit(ctx);
  } catch (ParseRuntimeException runtimeException) {
    throw runtimeException.getParseException();
  }
}
 
开发者ID:VerifAPS,项目名称:stvs,代码行数:26,代码来源:IntervalParser.java

示例10: compile

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
public static FilterPredicate compile(String predicateString){
    predicateString = predicateString.trim();
    if(predicateString.isEmpty()){
        return FilterPredicate.empty();
    }
    PredicateCompileErrorListener errorListener = new PredicateCompileErrorListener(predicateString);

    CharStream stream = CharStreams.fromString(predicateString);
    PredicateLexer lexer = new PredicateLexer(stream);
    lexer.removeErrorListener(ConsoleErrorListener.INSTANCE);
    lexer.addErrorListener(errorListener);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    PredicateParser parser = new PredicateParser(tokens);
    parser.removeErrorListener(ConsoleErrorListener.INSTANCE);
    parser.addErrorListener(errorListener);
    FilterPredicateVisitor filterPredicateVisitor = new FilterPredicateVisitor();
    return  filterPredicateVisitor.visit(parser.compilationUnit());
}
 
开发者ID:nRo,项目名称:DataFrame,代码行数:19,代码来源:PredicateCompiler.java

示例11: test

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
@Test
public void test() {

	final CharStream charStream = CharStreams.fromString("\r\nSELECT\r\n 1");

	final TSqlLexer lexer = new TSqlLexer(charStream);

	final CommonTokenStream stream = new CommonTokenStream(lexer);

	stream.fill();
	TSqlParser parser = new TSqlParser(stream);
	ParseTree child = parser.tsql_file().getChild(0);
	DefaultLinesProvider lines = new DefaultLinesProvider(stream);
	int line = lines.getLine(new ParsedNode(child));
	Assert.assertEquals(2, line);

}
 
开发者ID:gretard,项目名称:sonar-tsql-plugin,代码行数:18,代码来源:DefaultLinesProviderTest.java

示例12: parse

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
/**
 * Parses a source file using ANTLR4, and walks over the parse tree to
 * interpret this source file as a Java object.
 * 
 * @param c
 *            input character stream
 * @param path
 *            location of the file
 * @return an interpreted source file, or null in case of an error.
 */
@Nullable
private ReoFile<T> parse(CharStream c, String path) {
	ReoLexer lexer = new ReoLexer(c);
	CommonTokenStream tokens = new CommonTokenStream(lexer);
	ReoParser parser = new ReoParser(tokens);

	ErrorListener errListener = new ErrorListener(m);
	parser.removeErrorListeners();
	parser.addErrorListener(errListener);
	ParseTree tree = parser.file();
	if (errListener.hasError)
		return null;
	ParseTreeWalker walker = new ParseTreeWalker();
	listener.setFileName(path);
	walker.walk(listener, tree);
	return listener.getMain();
}
 
开发者ID:ReoLanguage,项目名称:Reo,代码行数:28,代码来源:Interpreter.java

示例13: parse

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
static MysqlParser.ScriptContext parse(CharStream cs) {
    MysqlLexer lexer = new MysqlLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    tokens.setTokenSource(lexer);
    MysqlParser parser = new MysqlParser(tokens);
    parser.setErrorHandler(new BailErrorStrategy());
    boolean success = false;
    try {
        MysqlParser.ScriptContext script = parser.script();
        success = true;
        return script;
    }
    finally {
        if (!success && (parser.lastStatement != null)) {
            _log.debug("last passed statement: {}", ((ParseTree)parser.lastStatement).getText());
        }
    }
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:19,代码来源:MysqlParserFactory.java

示例14: getBytes

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
private static byte[] getBytes(Literal_value_binaryContext rule) {
    Token token = rule.STRING_LITERAL().getSymbol();
    byte[] bytes = new byte[token.getStopIndex() - token.getStartIndex() - 1];
    CharStream cs = token.getInputStream();
    int pos = cs.index();
    cs.seek(token.getStartIndex() + 1);
    int j = 0;
    for (int i = 0; i < bytes.length; i++) {
        int ch = cs.LA(i + 1);
        if (ch == '\\') {
            i++;
            ch = cs.LA(i + 1);
            if (ch == '0') {
                ch = 0;
            }
            else if (ch == 'n') {
                ch = '\n';
            }
            else if (ch == 'r') {
                ch = '\r';
            }
            else if (ch == 'Z') {
                ch = '\032';
            }
        }
        bytes[j] = (byte) ch;
        j++;
    }
    cs.seek(pos);
    if (j != bytes.length) {
        // esacpe characters
        byte[] old = bytes;
        bytes = new byte[j];
        System.arraycopy(old, 0, bytes, 0, j);
    }
    return bytes;
}
 
开发者ID:waterguo,项目名称:antsdb,代码行数:38,代码来源:ExprGenerator.java

示例15: compileFiles

import org.antlr.v4.runtime.CharStream; //导入依赖的package包/类
private void compileFiles(List<RawFile> files, OOPSourceCodeModel srcModel, List<String> projectFileTypes) {
    for (RawFile file : files) {
        try {
            CharStream charStream = new ANTLRInputStream(file.content());
            GolangLexer lexer = new GolangLexer(charStream);
            TokenStream tokens = new CommonTokenStream(lexer);
            GolangParser parser = new GolangParser(tokens);
            SourceFileContext sourceFileContext = parser.sourceFile();
            parser.setErrorHandler(new BailErrorStrategy());
            parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
            ParseTreeWalker walker = new ParseTreeWalker();
            GolangBaseListener listener = new GoLangTreeListener(srcModel, projectFileTypes, file);
            walker.walk(listener, sourceFileContext);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:Zir0-93,项目名称:clarpse,代码行数:19,代码来源:ClarpseGoCompiler.java


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