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


Java CharStreams.fromStream方法代碼示例

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


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

示例1: 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

示例2: parseYangSource

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
private static StatementContext parseYangSource(final SourceIdentifier source, final InputStream stream)
        throws IOException, YangSyntaxErrorException {
    final YangStatementLexer lexer = new YangStatementLexer(CharStreams.fromStream(stream));
    final CommonTokenStream tokens = new CommonTokenStream(lexer);
    final YangStatementParser parser = new YangStatementParser(tokens);
    //disconnect from console error output
    parser.removeErrorListeners();

    final YangErrorListener errorListener = new YangErrorListener(source);
    parser.addErrorListener(errorListener);

    final StatementContext result = parser.statement();
    errorListener.validate();

    // Walk the resulting tree and replace each children with an immutable list, lowering memory requirements
    // and making sure the resulting tree will not get accidentally modified. An alternative would be to use
    // org.antlr.v4.runtime.Parser.TrimToSizeListener, but that does not make the tree immutable.
    ParseTreeWalker.DEFAULT.walk(MAKE_IMMUTABLE_LISTENER, result);

    return result;
}
 
開發者ID:opendaylight,項目名稱:yangtools,代碼行數:22,代碼來源:YangStatementStreamSource.java

示例3: parseStream

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
private static RulesetGroup parseStream(RulesetGroup rulesetGroup, InputStream is) 
    throws IOException {
CharStream input = CharStreams.fromStream( is );
NominalLexer nominalLexer = new NominalLexer( input );
CommonTokenStream tokens = new CommonTokenStream( nominalLexer );
NominalParser nominalParser = new NominalParser( tokens );
ParseTree parseTree = nominalParser.file();

NominalVisitor nominalVisitor = 
	new NominalVisitorImplementation( rulesetGroup );
nominalVisitor.visit( parseTree );

addDummyRulesets( rulesetGroup );

return rulesetGroup;
   }
 
開發者ID:sjbutler,項目名稱:nominal,代碼行數:17,代碼來源:RulesetGroupFactory.java

示例4: run

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static int run(final String data) throws IOException {
    CharStream input;
    if (data == null) {
        // Create a CharStream that reads from standard input.
        input = CharStreams.fromStream(System.in);
    } else {
        input = CharStreams.fromString(data);
    }

    // Create a lexer that feeds off of input CharStream.
    final ExprAdvancedLexer lexer = new ExprAdvancedLexer(input);

    // Create a buffer of tokens pulled from the lexer.
    final CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Create a parser that feeds off the tokens buffer.
    final ExprAdvancedParser parser = new ExprAdvancedParser(tokens);

    // Begin parsing at "prog" rule.
    final ParseTree tree = parser.prog();

    final ExprVisitor eval = new ExprVisitor();
    eval.visit(tree);
    return eval.getResult();
}
 
開發者ID:dzavodnikov,項目名稱:ANTLR4,代碼行數:26,代碼來源:MainVisitor.java

示例5: getWorkspaceContext

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static WorkspaceContext getWorkspaceContext(InputStream source) throws IOException {
    WorkspaceLexer l = new WorkspaceLexer(CharStreams.fromStream(source));
    WorkspaceParser p = new WorkspaceParser(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);
        }
    });
    WorkspaceContext ctx = p.workspace();
    return ctx;
}
 
開發者ID:ChiralBehaviors,項目名稱:Ultrastructure,代碼行數:17,代碼來源:WorkspacePresentation.java

示例6: testParse

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
@Test
public void testParse() throws Exception {
    WorkspaceLexer l = new WorkspaceLexer(CharStreams.fromStream(getClass().getResourceAsStream("/thing.wsp")));
    WorkspaceParser p = new WorkspaceParser(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);
        }
    });
    p.workspace();
}
 
開發者ID:ChiralBehaviors,項目名稱:Ultrastructure,代碼行數:17,代碼來源:TestParse.java

示例7: manifest

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static Spa manifest(String resource) throws IOException {
    SpaLexer l = new SpaLexer(CharStreams.fromStream(Utils.resolveResource(Spa.class,
                                                                           resource)));
    SpaParser p = new SpaParser(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);
        }
    });
    SpaContext spa = p.spa();
    SpaImporter importer = new SpaImporter();
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(importer, spa);
    return importer.getSpa();
}
 
開發者ID:ChiralBehaviors,項目名稱:Ultrastructure,代碼行數:21,代碼來源:Spa.java

示例8: read

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
@Nullable
@Override
public CharStream read(String name) {
    try {
        InputStream resource = readResource(name);
        if (resource != null) {
            return CharStreams.fromStream(resource);
        }
    } catch (Exception e) {
        LOGGER.error("Could not read {}", name, e);
    }
    return null;
}
 
開發者ID:protostuff,項目名稱:protostuff-compiler,代碼行數:14,代碼來源:ClasspathFileReader.java

示例9: parseLeafRefPathSource

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
private Path_argContext parseLeafRefPathSource(final InputStream stream) throws IOException,
        LeafRefYangSyntaxErrorException {
    final LeafRefPathLexer lexer = new LeafRefPathLexer(CharStreams.fromStream(stream));
    final CommonTokenStream tokens = new CommonTokenStream(lexer);
    final LeafRefPathParser parser = new LeafRefPathParser(tokens);
    parser.removeErrorListeners();

    final LeafRefPathErrorListener errorListener = new LeafRefPathErrorListener(module);
    parser.addErrorListener(errorListener);

    final Path_argContext result = parser.path_arg();
    errorListener.validate();
    return result;
}
 
開發者ID:opendaylight,項目名稱:yangtools,代碼行數:15,代碼來源:LeafRefPathParserImpl.java

示例10: run

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static int run(final String data) throws IOException {
    CharStream input;
    if (data == null) {
        // Create a CharStream that reads from standard input.
        input = CharStreams.fromStream(System.in);
    } else {
        input = CharStreams.fromString(data);
    }

    // Create a lexer that feeds off of input CharStream.
    final ExprAdvancedLexer lexer = new ExprAdvancedLexer(input);

    // Create a buffer of tokens pulled from the lexer.
    final CommonTokenStream tokens = new CommonTokenStream(lexer);

    // Create a parser that feeds off the tokens buffer.
    final ExprAdvancedParser parser = new ExprAdvancedParser(tokens);

    // Begin parsing at "prog" rule.
    final ParseTree tree = parser.prog();

    // Create a generic parse tree walker that can trigger callbacks.
    final ParseTreeWalker walker = new ParseTreeWalker();

    // Walk the tree created during the parse, trigger callbacks.
    final ExprListener listener = new ExprListener();
    walker.walk(listener, tree);
    return listener.getResult();
}
 
開發者ID:dzavodnikov,項目名稱:ANTLR4,代碼行數:30,代碼來源:MainListener.java

示例11: doParse

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
protected void doParse(final File inputFile, final VbParserParams params) throws IOException {
	final Charset charset = params.getCharset();

	LOG.info("Parsing file {} with charset {}.", inputFile.getName(), charset);

	final InputStream inputStream = new FileInputStream(inputFile);
	final VisualBasic6Lexer lexer = new VisualBasic6Lexer(CharStreams.fromStream(inputStream, charset));

	if (!params.getIgnoreSyntaxErrors()) {
		lexer.removeErrorListeners();
		lexer.addErrorListener(new ThrowingErrorListener());
	}

	final CommonTokenStream tokens = new CommonTokenStream(lexer);
	final VisualBasic6Parser parser = new VisualBasic6Parser(tokens);

	if (!params.getIgnoreSyntaxErrors()) {
		parser.removeErrorListeners();
		parser.addErrorListener(new ThrowingErrorListener());
	}

	final StartRuleContext startRule = parser.startRule();
	final File treeFile = new File(inputFile.getAbsolutePath() + TREE_SUFFIX);

	if (treeFile.exists()) {
		doCompareParseTree(treeFile, startRule, parser);
	}
}
 
開發者ID:uwol,項目名稱:vb6parser,代碼行數:29,代碼來源:VbParseTestRunnerImpl.java

示例12: compile

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
/**
 * Compile it to Java and save.
 * @throws IOException If fails
 */
public void compile() throws IOException {
    final String[] lines = new TextOf(this.input).asString().split("\n");
    final ANTLRErrorListener errors = new BaseErrorListener() {
        // @checkstyle ParameterNumberCheck (10 lines)
        @Override
        public void syntaxError(final Recognizer<?, ?> recognizer,
            final Object symbol, final int line,
            final int position, final String msg,
            final RecognitionException error) {
            throw new CompileException(
                String.format(
                    "[%d:%d] %s: \"%s\"",
                    line, position, msg, lines[line - 1]
                ),
                error
            );
        }
    };
    final ProgramLexer lexer = new ProgramLexer(
        CharStreams.fromStream(this.input.stream())
    );
    lexer.removeErrorListeners();
    lexer.addErrorListener(errors);
    final ProgramParser parser = new ProgramParser(
        new CommonTokenStream(lexer)
    );
    parser.removeErrorListeners();
    parser.addErrorListener(errors);
    final Tree tree = parser.program().ret;
    new IoCheckedScalar<>(
        new And(
            tree.java().entrySet(),
            path -> {
                new LengthOf(
                    new TeeInput(
                        path.getValue(),
                        this.target.apply(path.getKey())
                    )
                ).value();
            }
        )
    ).value();
}
 
開發者ID:yegor256,項目名稱:eo,代碼行數:48,代碼來源:Program.java

示例13: getFull

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static AntrlResult getFull(InputStream stream) throws IOException {
	final CharStream charStream = CharStreams.fromStream(stream);
	return getFromStream(charStream);
}
 
開發者ID:gretard,項目名稱:sonar-tsql-plugin,代碼行數:5,代碼來源:Antlr4Utils.java

示例14: parseRegexList

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
public static RegexList parseRegexList(URL resourceURL, Optional<Path> customResourceDir) throws IOException {
	InputStream is = resourceURL.openStream();
	CharStream  input = CharStreams.fromStream(is);
	return parseRegexList(input, resourceURL, customResourceDir);

}
 
開發者ID:nantesnlp,項目名稱:uima-tokens-regex,代碼行數:7,代碼來源:TokensRegex.java

示例15: parseFile

import org.antlr.v4.runtime.CharStreams; //導入方法依賴的package包/類
protected void parseFile(final File inputFile, final Program program, final VbParserParams params)
		throws IOException {
	if (!inputFile.isFile()) {
		LOG.warn("Could not find file {}", inputFile.getAbsolutePath());
	} else {
		final Charset charset = params.getCharset();

		LOG.info("Parsing file {} with charset {}.", inputFile.getName(), charset);

		final InputStream inputStream = new FileInputStream(inputFile);
		final VisualBasic6Lexer lexer = new VisualBasic6Lexer(CharStreams.fromStream(inputStream, charset));

		if (!params.getIgnoreSyntaxErrors()) {
			// register an error listener, so that preprocessing stops on errors
			lexer.removeErrorListeners();
			lexer.addErrorListener(new ThrowingErrorListener());
		}

		// get a list of matched tokens
		final CommonTokenStream tokens = new CommonTokenStream(lexer);

		// pass the tokens to the parser
		final VisualBasic6Parser parser = new VisualBasic6Parser(tokens);

		if (!params.getIgnoreSyntaxErrors()) {
			// register an error listener, so that preprocessing stops on errors
			parser.removeErrorListeners();
			parser.addErrorListener(new ThrowingErrorListener());
		}

		// specify our entry point
		final StartRuleContext ctx = parser.startRule();

		// determine the module name
		final String declaredModuleName = analyzeDeclaredModuleName(ctx);
		final String moduleName;

		if (declaredModuleName != null && !declaredModuleName.isEmpty()) {
			moduleName = declaredModuleName;
		} else {
			moduleName = getModuleName(inputFile);
		}

		// analyze contained modules and types
		final boolean isClazzModule = isClazzModule(inputFile);
		final boolean isStandardModule = isStandardModule(inputFile);

		final String input = FileUtils.readFileToString(inputFile, charset);
		final List<String> lines = splitLines(input);

		final ParserVisitor visitor = new VbModuleVisitorImpl(moduleName, lines, isClazzModule, isStandardModule,
				tokens, program);

		LOG.info("Collecting types in file {}.", inputFile.getName());
		visitor.visit(ctx);
	}
}
 
開發者ID:uwol,項目名稱:vb6parser,代碼行數:58,代碼來源:VbParserRunnerImpl.java


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