/** * Creates a {@link CharStream} given a string containing a * path to a UTF-8 file on disk. * * Reads the entire contents of the file into the result before returning. */ public static CharStream fromFileName(String fileName) throws IOException { return fromFileName(fileName, Charset.forName("UTF-8")); }
/** * parse the given input File with the given encoding * * @param inputFile * @param encoding * @return - the parse Tree * @throws IOException */ public ParseTree parse(File inputFile, String encoding) throws Exception { this.setSourceFileName(inputFile.getPath()); in = CharStreams.fromFileName(sourceFileName); inputText = FileUtils.readFileToString(inputFile, encoding); ParseTree result = parse(in, inputText); return result; }
public static Properties parse(String fileName) throws IOException, ConfigException { Configuration conf = new Configuration(); return conf.runparsing(CharStreams.fromFileName(fileName)); }
@Override public List<Triple> fromSiDIFFile(File sidifFile) throws Exception { this.setSourceFileName(sidifFile.getPath()); CharStream in = CharStreams.fromFileName(this.getSourceFileName()); List<Triple> tripleList=fromCharStream(in); return tripleList; }
/** * Creates a new Template instance from a given file. * * @param file * the file holding the Liquid source. */ private Template(File file, Map<String, Tag> tags, Map<String, Filter> filters, ParseSettings parseSettings) throws IOException { this.tags = tags; this.filters = filters; this.parseSettings = parseSettings; CharStream stream = CharStreams.fromFileName(file.getAbsolutePath()); try { this.templateSize = stream.size(); LiquidLexer lexer = new LiquidLexer(stream, parseSettings.stripSpacesAroundTags, parseSettings.stripSingleLine); root = parse(lexer); } catch (Exception e) { throw new RuntimeException("could not parse input from " + file, e); } }
public static void main(String[] args) { try { TLLexer lexer = new TLLexer(CharStreams.fromFileName("src/main/tl/test.tl")); TLParser parser = new TLParser(new CommonTokenStream(lexer)); parser.setBuildParseTree(true); ParseTree tree = parser.parse(); Scope scope = new Scope(); Map<String, Function> functions = new HashMap<>(); SymbolVisitor symbolVisitor = new SymbolVisitor(functions); symbolVisitor.visit(tree); EvalVisitor visitor = new EvalVisitor(scope, functions); visitor.visit(tree); } catch (Exception e) { if (e.getMessage() != null) { System.err.println(e.getMessage()); } else { e.printStackTrace(); } } } }
if (this.override == null) { try { stream = CharStreams.fromFileName(getFilename()); } catch (InvalidPathException e) { throw new IOException(e);