Search in sources :

Example 1 with ParseTable

use of org.spoofax.jsglr.client.ParseTable in project spoofax by metaborg.

the class JSGLR1FileParseTableProvider method parseTable.

@Override
public ParseTable parseTable() throws IOException {
    if (parseTable != null) {
        return parseTable;
    }
    resource.refresh();
    if (!resource.exists()) {
        throw new IOException("Could not load parse table from " + resource + ", file does not exist");
    }
    try (final InputStream stream = resource.getContent().getInputStream()) {
        final TermReader termReader = new TermReader(termFactory);
        IStrategoTerm parseTableTerm = termReader.parseFromStream(stream);
        FileObject persistedTable = resource.getParent().resolveFile("table.bin");
        if (persistedTable.exists()) {
            parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable);
        } else {
            parseTable = new ParseTable(parseTableTerm, termFactory);
        }
    } catch (Exception e) {
        throw new IOException("Could not load parse table from " + resource, e);
    }
    return parseTable;
}
Also used : ParseTable(org.spoofax.jsglr.client.ParseTable) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) InputStream(java.io.InputStream) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) TermReader(org.spoofax.terms.io.binary.TermReader)

Example 2 with ParseTable

use of org.spoofax.jsglr.client.ParseTable in project spoofax by metaborg.

the class JSGLR1IncrementalParseTableProvider method parseTable.

@Override
public ParseTable parseTable() throws IOException {
    if (parseTable != null) {
        return parseTable;
    }
    resource.refresh();
    if (!resource.exists()) {
        throw new IOException("Could not load parse table from " + resource + ", file does not exist");
    }
    try (final InputStream stream = resource.getContent().getInputStream()) {
        final TermReader termReader = new TermReader(termFactory);
        final IStrategoTerm parseTableTerm = termReader.parseFromStream(stream);
        FileObject persistedTable = resource.getParent().resolveFile("table.bin");
        if (persistedTable.exists()) {
            if (referenceTable != null) {
                parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable, referenceTable);
            } else {
                parseTable = new ParseTable(parseTableTerm, termFactory, persistedTable);
            }
        } else {
            parseTable = new ParseTable(parseTableTerm, termFactory);
        }
    } catch (Exception e) {
        throw new IOException("Could not load parse table from " + resource, e);
    }
    return parseTable;
}
Also used : ParseTable(org.spoofax.jsglr.client.ParseTable) IStrategoTerm(org.spoofax.interpreter.terms.IStrategoTerm) InputStream(java.io.InputStream) IOException(java.io.IOException) FileObject(org.apache.commons.vfs2.FileObject) IOException(java.io.IOException) TermReader(org.spoofax.terms.io.binary.TermReader)

Aggregations

IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FileObject (org.apache.commons.vfs2.FileObject)2 IStrategoTerm (org.spoofax.interpreter.terms.IStrategoTerm)2 ParseTable (org.spoofax.jsglr.client.ParseTable)2 TermReader (org.spoofax.terms.io.binary.TermReader)2