List of usage examples for org.antlr.v4.runtime CharStreams fromPath
public static CharStream fromPath(Path path) throws IOException
From source file:edu.clemson.cs.rsrg.misc.Utilities.java
License:Open Source License
/** * <p>Converts a regular {@link File} object to the * {@link ResolveFile} accepted by the compiler.</p> * * @param file The Java File object./*from ww w. j av a2 s.com*/ * @param moduleType The extension of the file. * @param workspacePath The current RESOLVE workspace path. * * @return A {@link ResolveFile} object representing the file. * * @throws IOException There was some sort of error during the conversion. */ public static ResolveFile convertToResolveFile(File file, ModuleType moduleType, String workspacePath) throws IOException { // Convert to the internal representation of a RESOLVE file String name = Utilities.getFileName(file.getName(), moduleType); List<String> pkgList = Utilities.getPackageList(file.getAbsolutePath(), workspacePath); CharStream inputStream = CharStreams.fromPath(file.toPath()); File parentFile = file.getParentFile(); return new ResolveFile(new ResolveFileBasicInfo(name, parentFile.getName()), moduleType, inputStream, parentFile.toPath(), pkgList, file.getAbsolutePath()); }
From source file:org.flightgear.clgen.CLGen.java
License:Open Source License
private void run() throws IOException, GeneratorException { CLGenLexer lexer = new CLGenLexer(CharStreams.fromPath(input)); CommonTokenStream tokenStream = new CommonTokenStream(lexer); errorListener = new ErrorListener(tokenStream); SpecificationContext context = parse(tokenStream); if (errors != 0) System.err.format("Generation failed with %d error%s.\n", errors, errors != 1 ? "s" : ""); else {/* ww w .j a v a2 s . com*/ Map<String, Item> items = buildItems(context); AbstractSyntaxTree ast = buildAST(items, context); if (errors > 0) { System.err.format("Generation failed with %d error%s.\n", errors, errors != 1 ? "s" : ""); return; } UsageVisitor usageVisitor = new UsageVisitor(items); ast.accept(usageVisitor); warnings += usageVisitor.getNumberOfWarnings(); if (ast.isWrapper()) ast.accept(new MultiXmlVisitor(input.toAbsolutePath().getParent())); else ast.accept(new XmlVisitor(input.toAbsolutePath().getParent())); ast.accept(new DotVisitor(input.toAbsolutePath().getParent())); ast.accept(new PdfVisitor(input.toAbsolutePath().getParent())); if (warnings > 0) System.out.format("Generation complete with %d warning%s.\n", warnings, warnings != 1 ? "s" : ""); else System.out.println("Generation complete."); } }