Search in sources :

Example 1 with Lexer

use of de.prob.core.sablecc.lexer.Lexer in project probparsers by bendisposto.

the class ProBResultParser method parse.

public static Start parse(final String prologAnswer) throws ResultParserException {
    if (prologAnswer.length() == 0)
        throw new ResultParserException("Received empty Result", null);
    final PushbackReader codeReader = new PushbackReader(new StringReader(prologAnswer), prologAnswer.length());
    final Lexer lexer = new Lexer(codeReader);
    final Parser parser = new Parser(lexer);
    Start parseResult = null;
    try {
        parseResult = parser.parse();
    } catch (final ParserException e) {
        String message = "Internal Error while parsing ProB answer. This ist most likely a bug in the Result-Parser. String was: '" + prologAnswer + "'. Last Token was '" + e.getToken() + "': " + e.getLocalizedMessage();
        throw new ResultParserException(message, e);
    } catch (final LexerException e) {
        String message = "Internal Error while parsing ProB answer. This ist most likely a bug in the Result-Parser String was: '" + prologAnswer + "': " + e.getLocalizedMessage();
        throw new ResultParserException(message, e);
    } catch (final IOException e) {
        String message = "Internal Error while parsing ProB answer. This ist most likely a bug in the Result-Parser String was: " + prologAnswer + "': " + e.getLocalizedMessage();
        throw new ResultParserException(message, e);
    }
    return parseResult;
}
Also used : ParserException(de.prob.core.sablecc.parser.ParserException) Lexer(de.prob.core.sablecc.lexer.Lexer) Start(de.prob.core.sablecc.node.Start) StringReader(java.io.StringReader) IOException(java.io.IOException) LexerException(de.prob.core.sablecc.lexer.LexerException) PushbackReader(java.io.PushbackReader) Parser(de.prob.core.sablecc.parser.Parser)

Aggregations

Lexer (de.prob.core.sablecc.lexer.Lexer)1 LexerException (de.prob.core.sablecc.lexer.LexerException)1 Start (de.prob.core.sablecc.node.Start)1 Parser (de.prob.core.sablecc.parser.Parser)1 ParserException (de.prob.core.sablecc.parser.ParserException)1 IOException (java.io.IOException)1 PushbackReader (java.io.PushbackReader)1 StringReader (java.io.StringReader)1