Example usage for org.antlr.v4.runtime CharStreams fromFileName

List of usage examples for org.antlr.v4.runtime CharStreams fromFileName

Introduction

In this page you can find the example usage for org.antlr.v4.runtime CharStreams fromFileName.

Prototype

public static CharStream fromFileName(String fileName) throws IOException 

Source Link

Document

Creates a CharStream given a string containing a path to a UTF-8 file on disk.

Usage

From source file:greycat.language.Model.java

License:Open Source License

public void parse(File content) throws Exception {
    internal_parse(CharStreams.fromFileName(content.getAbsolutePath()), new Resolver() {
        @Override/*  w ww .j a  v  a 2  s.co  m*/
        public CharStream resolver(String name) {
            try {
                File subFile = new File(content.getParentFile().getCanonicalFile(), name);
                if (subFile.exists()) {
                    return CharStreams.fromFileName(subFile.getAbsolutePath());
                } else {
                    subFile = new File(content.getParentFile().getCanonicalFile(), name + ".gcm");
                    if (subFile.exists()) {
                        return CharStreams.fromFileName(subFile.getAbsolutePath());
                    } else {
                        return null;
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
                return null;
            }
        }
    });
}

From source file:gsp.GSPMain.java

/**
 * @param args the command line arguments
 * @throws java.io.IOException/*from  w  w  w.ja v  a2  s  .co  m*/
 */
public static void main(String[] args) throws IOException {
    // TODO code application logic here

    CharStream cs = CharStreams.fromFileName("inputBlocks.txt");

    gspGrammarLexer lexer = new gspGrammarLexer(cs);
    //lexer.removeErrorListeners();

    CommonTokenStream tokens = new CommonTokenStream(lexer);
    gspGrammarParser parser = new gspGrammarParser(tokens);
    gspGrammarParser.ProgramContext contexto = parser.program();

    ParseTree tree = contexto;

    int errorsCount = parser.getNumberOfSyntaxErrors();
    System.out.println(errorsCount);
    if (errorsCount == 0) {
        ParserGSP gsp = new ParserGSP();
        gsp.visit(tree);

        System.out.println(gsp.getPredicates());
        System.out.println("Actions");
        for (Action a : gsp.getActions()) {
            System.out.println("----------");
            System.out.println(a);
            System.out.println("----------");
        }

        GSP algorithim = new GSP(gsp.getInitialState(), gsp.getGoalState(), gsp.getActions());
    }
}