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


Java CharStreams類代碼示例

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


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

示例1: parse

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

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
/**
 * Returns an ExecutableCode that can then be run by the processor. If the given code contains
 * data section, linker will only generate memory addresses. Without loading process, referenced
 * data will be unpredictable.
 *
 * @param code The code that will be linked.
 *
 * @return The executable code.
 *
 * @throws LabelError If an undefined label used or duplicate labels exist.
 * @see Loader#load(Linker.ExecutableCode)
 */
public ExecutableCode link(String code) throws LabelError {
    definedBranches.clear();
    definedData.clear();
    addressBook.clear();
    secondPass = false;
    this.code = parseCode(code);
    AssemblerLexer lexer = new AssemblerLexer(CharStreams.fromString(code));
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    AssemblerParser parser = new AssemblerParser(tokens);
    AssemblerParser.ProgContext program = parser.prog();
    visit(program);
    secondPass = true;
    visit(program);
    List<Data> temp = new ArrayList<>(definedData.size());
    definedData.forEach((label, data) -> {
        temp.add(data);
    });
    return new ExecutableCode(this.code, temp);
}
 
開發者ID:kasirgalabs,項目名稱:ETUmulator,代碼行數:32,代碼來源:Linker.java

示例5: parse

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

示例6: evaluate

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
public static String evaluate(String templateString, Map<String, Object> environment) {
    final Scanner s = new Scanner(templateString);
    // TODO: This is a hack that fails if a string literal contains "}"
    // TODO: It's because i couldn't be bothered nesting grammars.
    s.useDelimiter("((?!\\\\)\\$\\{)|(})");

    StringBuilder ret = new StringBuilder();
    boolean isInsideExpr = templateString.startsWith("${");
    while(s.hasNext()) {
        final String str = s.next();

        if (isInsideExpr) {
            final JsLikeExpressionLexer lexer = new JsLikeExpressionLexer(CharStreams.fromString(str));
            final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
            final JsLikeExpressionParser parser = new JsLikeExpressionParser(tokenStream);


            final TemplateStringEvaluatorVisitor visitor = new TemplateStringEvaluatorVisitor(environment);

            ret.append(parser.expression().accept(visitor).toString());
        } else {
            ret.append(str);
        }

        isInsideExpr = !isInsideExpr;
    }

    return ret.toString();
}
 
開發者ID:adamkewley,項目名稱:jobson,代碼行數:30,代碼來源:TemplateStringEvaluator.java

示例7: parseUserAgent

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
private UserAgentContext parseUserAgent(UserAgent userAgent) {
    String userAgentString = EvilManualUseragentStringHacks.fixIt(userAgent.getUserAgentString());

    CodePointCharStream input = CharStreams.fromString(userAgentString);
    UserAgentLexer lexer = new UserAgentLexer(input);

    CommonTokenStream tokens = new CommonTokenStream(lexer);

    UserAgentParser parser = new UserAgentParser(tokens);

    if (!verbose) {
        lexer.removeErrorListeners();
        parser.removeErrorListeners();
    }
    lexer.addErrorListener(userAgent);
    parser.addErrorListener(userAgent);

    return parser.userAgent();
}
 
開發者ID:nielsbasjes,項目名稱:yauaa,代碼行數:20,代碼來源:UserAgentTreeFlattener.java

示例8: compile

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

示例9: testExampleFieldCondition

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
@Test
public void testExampleFieldCondition() throws Exception {
  ScoreLexer l = new ScoreLexer(CharStreams.fromString(expression));
  ScoreParser p = new ScoreParser(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(String.format(
          "Failed to parse at line %d position %d due to %s", line, charPositionInLine, msg), e);
    }
  });
  ScoreTranslator visitor = new ScoreTranslator();
  AnyExpressionContext ctx = p.anyExpression();
  String text = visitor.visitAnyExpression(ctx);
  System.out.println(text);
}
 
開發者ID:FIXTradingCommunity,項目名稱:fix-orchestra,代碼行數:18,代碼來源:ScoreTranslatorTest.java

示例10: testExampleFieldCondition

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
@Test
public void testExampleFieldCondition() throws Exception {
  ScoreLexer l = new ScoreLexer(CharStreams.fromString(fieldCondition));
  ScoreParser p = new ScoreParser(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(String.format(
          "Failed to parse at line %d position %d due to %s", line, charPositionInLine, msg), e);
    }
  });
  ScoreBaseVisitor<Object> visitor = new ScoreBaseVisitor<>();
  AnyExpressionContext ctx = p.anyExpression();
  Object expression = visitor.visitAnyExpression(ctx);
  //System.out.println(expression.getClass().getSimpleName());
}
 
開發者ID:FIXTradingCommunity,項目名稱:fix-orchestra,代碼行數:18,代碼來源:DslExpressionTest.java

示例11: combineInput

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
private static Program combineInput(boolean literate, String... fileNames) throws IOException {
	final Program result = new Program();

	for (String fileName : fileNames) {
		CharStream stream;
		if (!literate) {
			stream = CharStreams.fromFileName(fileName);
		} else {
			stream = CharStreams.fromChannel(
				streamToChannel(literate(lines(Paths.get(fileName)))),
				4096,
				CodingErrorAction.REPLACE,
				fileName
			);
		}
		result.accumulate(PARSER.parse(stream));
	}

	return result;
}
 
開發者ID:alpha-asp,項目名稱:Alpha,代碼行數:21,代碼來源:Main.java

示例12: createRequest

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
public static FillerRequest createRequest(final SourceLinesProvider linesProvider, final InputFile file, final Charset encoding)
		throws IOException, FileNotFoundException {
	final CharStream mainStream = CharStreams.fromPath(file.path(), encoding);
	final CharStream charStream = new CaseChangingCharStream(mainStream, true);
	final TSqlLexer lexer = new TSqlLexer(charStream);

	lexer.removeErrorListeners();

	final CommonTokenStream stream = new CommonTokenStream(lexer);

	stream.fill();
	final TSqlParser parser = new TSqlParser(stream);
	parser.removeErrorListeners();
	final ParseTree root = parser.tsql_file();
	final FillerRequest antrlFile = new FillerRequest(file, stream, root,
			linesProvider.getLines(new FileInputStream(file.file()), encoding));
	return antrlFile;
}
 
開發者ID:gretard,項目名稱:sonar-tsql-plugin,代碼行數:19,代碼來源:PluginHelper.java

示例13: test

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

示例14: parseKuduExpression

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
public void parseKuduExpression() throws Exception
{
  KuduSQLExpressionLexer lexer = new KuduSQLExpressionLexer(CharStreams.fromString(sqlExpresssion));
  CommonTokenStream tokens = new CommonTokenStream( lexer );
  parser = new KuduSQLParser( tokens );
  errorListener = parser.getKuduSQLExpressionErrorListener();
  ParseTree parserTree = parser.kudusqlexpression();
  if (!errorListener.isSyntaxError()) {
    ParseTreeWalker parseTreeWalker = new ParseTreeWalker();
    kuduSQLParseTreeListener = new KuduSQLParseTreeListener();
    kuduSQLParseTreeListener.setColumnSchemaList(allColumnsForThisTable);
    try {
      parseTreeWalker.walk(kuduSQLParseTreeListener, parserTree);
    } catch (Exception ex) {
      LOG.error(" The supplied SQL expression could not be parsed because " + ex.getMessage(),ex);
      errorListener.setSyntaxError(true);
    }
  } else {
    LOG.error(" Syntax error present in the Kudu SQL expression. Hence not processing");
    List<String> allRegisteredSyntaxErrors = errorListener.getListOfErrorMessages();
    for (String syntaxErrorMessage : allRegisteredSyntaxErrors) {
      LOG.error(" Error : " + syntaxErrorMessage  + " in SQL expression \"" + sqlExpresssion + " \"");
    }
  }
}
 
開發者ID:apache,項目名稱:apex-malhar,代碼行數:26,代碼來源:SQLToKuduPredicatesTranslator.java

示例15: read

import org.antlr.v4.runtime.CharStreams; //導入依賴的package包/類
@Nullable
@Override
public CharStream read(String name) {
    for (Path prefix : pathList) {
        Path path = prefix.resolve(name);
        if (Files.isRegularFile(path)) {
            try {
                byte[] bytes = Files.readAllBytes(path);
                String result = new String(bytes, StandardCharsets.UTF_8);
                return CharStreams.fromString(result);
            } catch (IOException e) {
                LOGGER.trace("Could not read {}", path, e);
            }
        }
    }
    return null;
}
 
開發者ID:protostuff,項目名稱:protostuff-compiler,代碼行數:18,代碼來源:LocalFileReader.java


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