Search in sources :

Example 1 with ParseException

use of fr.lirmm.graphik.graal.api.io.ParseException in project graal by graphik-team.

the class DlgpParser method parse.

// /////////////////////////////////////////////////////////////////////////
// PRIVATE
// /////////////////////////////////////////////////////////////////////////
private static Object parse(String s) throws ParseException {
    InMemoryStream<Object> stream = new QueueStream<Object>();
    Producer p = new Producer(new StringReader(s), stream);
    try {
        p.run();
    } catch (Throwable t) {
        throw new DlgpParseException(t);
    }
    if (!stream.hasNext()) {
        throw new DlgpParseException("No statement found.");
    }
    Object o = null;
    do {
        o = stream.next();
    } while (o instanceof Directive || o instanceof Prefix);
    if (stream.hasNext()) {
        throw new DlgpParseException("Too much statements.");
    }
    stream.close();
    if (o instanceof ParseException) {
        throw (ParseException) o;
    }
    return o;
}
Also used : QueueStream(fr.lirmm.graphik.util.stream.QueueStream) StringReader(java.io.StringReader) Prefix(fr.lirmm.graphik.util.Prefix) ParseException(fr.lirmm.graphik.graal.api.io.ParseException)

Aggregations

ParseException (fr.lirmm.graphik.graal.api.io.ParseException)1 Prefix (fr.lirmm.graphik.util.Prefix)1 QueueStream (fr.lirmm.graphik.util.stream.QueueStream)1 StringReader (java.io.StringReader)1