Search in sources :

Example 1 with QueueStream

use of fr.lirmm.graphik.util.stream.QueueStream in project graal by graphik-team.

the class DlgpParser method parseAtomSet.

public static CloseableIterator<Atom> parseAtomSet(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);
    }
    return new AtomCloseableIteratorWrapperHandlingParseException(stream);
}
Also used : QueueStream(fr.lirmm.graphik.util.stream.QueueStream) StringReader(java.io.StringReader)

Example 2 with QueueStream

use of fr.lirmm.graphik.util.stream.QueueStream 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

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