Search in sources :

Example 6 with ParserException

use of de.be4.eventbalg.core.parser.parser.ParserException in project probparsers by bendisposto.

the class EventBParser method createEventBParseException.

private EventBParseException createEventBParseException(final ParserException e) {
    final Token token = e.getToken();
    String message = e.getMessage();
    final boolean expectingFound = message.indexOf("expecting") >= 0;
    /*
		 * Special error message for misplaced comments.
		 */
    if (expectingFound && token instanceof TComment) {
        message = MSG_COMMENT_PLACEMENT;
    }
    /*
		 * Replace some token names...
		 */
    message = message.replaceFirst(" at", " @");
    return new EventBParseException(token, message);
}
Also used : Token(de.be4.eventbalg.core.parser.node.Token) IToken(de.hhu.stups.sablecc.patch.IToken) TComment(de.be4.eventbalg.core.parser.node.TComment)

Example 7 with ParserException

use of de.be4.eventbalg.core.parser.parser.ParserException in project probparsers by bendisposto.

the class EventBParser method createEventBParseException.

private EventBParseException createEventBParseException(final ParserException e) {
    final Token token = e.getToken();
    String message = e.getMessage();
    final boolean expectingFound = message.indexOf("expecting") >= 0;
    /*
		 * Special error message for misplaced comments.
		 */
    if (expectingFound && token instanceof TComment) {
        message = MSG_COMMENT_PLACEMENT;
    }
    /*
		 * Replace some token names...
		 */
    message = message.replaceFirst(" at", " @");
    return new EventBParseException(token, message);
}
Also used : Token(de.be4.eventb.core.parser.node.Token) IToken(de.hhu.stups.sablecc.patch.IToken) TComment(de.be4.eventb.core.parser.node.TComment)

Example 8 with ParserException

use of de.be4.eventbalg.core.parser.parser.ParserException in project probparsers by bendisposto.

the class LTLFormulaVisitor method parseLTLFormula.

public static Start parseLTLFormula(String ltlFormula) throws ParserException, LexerException, IOException {
    StringReader reader = new StringReader(ltlFormula);
    PushbackReader r = new PushbackReader(reader);
    Lexer l = new LtlLexer(r);
    Parser p = new Parser(l);
    Start ast = null;
    ast = p.parse();
    return ast;
}
Also used : Lexer(de.be4.ltl.core.parser.lexer.Lexer) LtlLexer(de.be4.ltl.core.parser.internal.LtlLexer) Start(de.be4.ltl.core.parser.node.Start) StringReader(java.io.StringReader) LtlLexer(de.be4.ltl.core.parser.internal.LtlLexer) PushbackReader(java.io.PushbackReader) Parser(de.be4.ltl.core.parser.parser.Parser) BParser(de.be4.classicalb.core.parser.BParser)

Example 9 with ParserException

use of de.be4.eventbalg.core.parser.parser.ParserException in project probparsers by bendisposto.

the class LtlParser method parseFormula.

protected Start parseFormula(final String formula) throws LtlParseException, IOException {
    StringReader reader = new StringReader(formula);
    PushbackReader r = new PushbackReader(reader);
    Lexer l = new LtlLexer(r);
    Parser p = new Parser(l);
    Start ast = null;
    try {
        ast = p.parse();
    } catch (ParserException e) {
        final UniversalToken token = UniversalToken.createToken(e.getToken());
        throw new LtlParseException(token, e.getLocalizedMessage());
    } catch (LexerException e) {
        throw new LtlParseException(null, e.getLocalizedMessage());
    }
    return ast;
}
Also used : ParserException(de.be4.ltl.core.parser.parser.ParserException) LtlLexer(de.be4.ltl.core.parser.internal.LtlLexer) Lexer(de.be4.ltl.core.parser.lexer.Lexer) UniversalToken(de.be4.ltl.core.parser.internal.UniversalToken) Start(de.be4.ltl.core.parser.node.Start) StringReader(java.io.StringReader) LexerException(de.be4.ltl.core.parser.lexer.LexerException) LtlLexer(de.be4.ltl.core.parser.internal.LtlLexer) PushbackReader(java.io.PushbackReader) Parser(de.be4.ltl.core.parser.parser.Parser)

Example 10 with ParserException

use of de.be4.eventbalg.core.parser.parser.ParserException in project probparsers by bendisposto.

the class BParser method eparse.

public Start eparse(String input, IDefinitions context) throws BCompoundException, LexerException, IOException {
    final Reader reader = new StringReader(input);
    Start ast = null;
    List<String> ids = new ArrayList<>();
    final DefinitionTypes defTypes = new DefinitionTypes();
    defTypes.addAll(context.getTypes());
    BLexer bLexer = new BLexer(new PushbackReader(reader, BLexer.PUSHBACK_BUFFER_SIZE), defTypes);
    bLexer.setParseOptions(parseOptions);
    Token t;
    do {
        t = bLexer.next();
        if (t instanceof TIdentifierLiteral) {
            if (!ids.contains(t.getText())) {
                ids.add(t.getText());
            }
        }
    } while (!(t instanceof EOF));
    Parser p = new Parser(new EBLexer(input, BigInteger.ZERO, ids, defTypes));
    boolean ok;
    try {
        ast = p.parse();
        ok = true;
    } catch (Exception e) {
        handleException(e);
        ok = false;
    }
    BigInteger b = new BigInteger("2");
    b = b.pow(ids.size());
    b = b.subtract(BigInteger.ONE);
    while (!ok && b.compareTo(BigInteger.ZERO) > 0) {
        p = new Parser(new EBLexer(input, b, ids, defTypes));
        try {
            ast = p.parse();
            ok = true;
        } catch (ParserException e) {
            b = b.subtract(BigInteger.ONE);
            handleException(e);
        }
    }
    return ast;
}
Also used : ParserException(de.be4.classicalb.core.parser.parser.ParserException) Start(de.be4.classicalb.core.parser.node.Start) ArrayList(java.util.ArrayList) Reader(java.io.Reader) StringReader(java.io.StringReader) PushbackReader(java.io.PushbackReader) Token(de.be4.classicalb.core.parser.node.Token) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) LexerException(de.be4.classicalb.core.parser.lexer.LexerException) IOException(java.io.IOException) ParserException(de.be4.classicalb.core.parser.parser.ParserException) PushbackReader(java.io.PushbackReader) Parser(de.be4.classicalb.core.parser.parser.Parser) StringReader(java.io.StringReader) BigInteger(java.math.BigInteger) EOF(de.be4.classicalb.core.parser.node.EOF)

Aggregations

PushbackReader (java.io.PushbackReader)7 StringReader (java.io.StringReader)7 IToken (de.hhu.stups.sablecc.patch.IToken)4 IOException (java.io.IOException)4 Reader (java.io.Reader)4 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)2 Start (de.be4.classicalb.core.parser.node.Start)2 Token (de.be4.classicalb.core.parser.node.Token)2 ParserException (de.be4.classicalb.core.parser.parser.ParserException)2 LtlLexer (de.be4.ltl.core.parser.internal.LtlLexer)2 UniversalToken (de.be4.ltl.core.parser.internal.UniversalToken)2 Lexer (de.be4.ltl.core.parser.lexer.Lexer)2 Start (de.be4.ltl.core.parser.node.Start)2 Parser (de.be4.ltl.core.parser.parser.Parser)2 IParser (de.hhu.stups.sablecc.patch.IParser)2 ITokenListContainer (de.hhu.stups.sablecc.patch.ITokenListContainer)2 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)2 SourcePositions (de.hhu.stups.sablecc.patch.SourcePositions)2 SourcecodeRange (de.hhu.stups.sablecc.patch.SourcecodeRange)2 InputStreamReader (java.io.InputStreamReader)2