Search in sources :

Example 6 with LexerException

use of de.be4.ltl.core.parser.lexer.LexerException in project probparsers by bendisposto.

the class PreLexer method collectRhs.

private void collectRhs() throws LexerException, IOException {
    if (state.equals(State.DEFINITIONS_RHS) || (previousState != null && previousState.equals(State.DEFINITIONS_RHS))) {
        if (rhsToken == null) {
            // starting a new definition rhs
            rhsToken = new TRhsBody("", -1, -1);
            rhsBuffer = new StringBuilder();
        } else {
            final State nextState = getNextState();
            // end of rhs reached?
            if (nextState != null) {
                // push current token back into reader
                try {
                    unread(token);
                } catch (IOException e) {
                    throw new IOException("Pushback buffer overflow on Token: " + token.getText());
                }
                // prepare rhs_body token to be the current one
                ((Token) rhsToken).setText(rhsBuffer.toString());
                token = rhsToken;
                rhsToken = null;
                rhsBuffer = null;
                state = nextState;
            } else {
                // first token after "==" sets start position
                if (rhsToken.getLine() == -1) {
                    rhsToken.setLine(token.getLine());
                    rhsToken.setPos(token.getPos());
                }
                rhsBuffer.append(token.getText());
                token = null;
            }
        }
    }
}
Also used : TRhsBody(de.be4.classicalb.core.preparser.node.TRhsBody) Token(de.be4.classicalb.core.preparser.node.Token) IOException(java.io.IOException)

Example 7 with LexerException

use of de.be4.ltl.core.parser.lexer.LexerException in project probparsers by bendisposto.

the class EBLexer method filter.

@Override
protected void filter() throws LexerException, IOException {
    super.filter();
    if (token != null && token instanceof TIdentifierLiteral && v.get(token.getText())) {
        Queue<IToken> ts = getNextList();
        List<IToken> toks = getTokenList();
        int l = token.getLine();
        int p = token.getPos();
        TLeftPar t1 = new TLeftPar(l, p);
        ts.add(t1);
        toks.add(t1);
        ts.add(token);
        toks.add(token);
        TEqual t2 = new TEqual("=", l, p);
        ts.add(t2);
        toks.add(t2);
        TTrue t3 = new TTrue("TRUE", l, p);
        ts.add(t3);
        toks.add(t3);
        TRightPar t4 = new TRightPar(l, p);
        ts.add(t4);
        toks.add(t4);
        token = null;
    }
}
Also used : IToken(de.hhu.stups.sablecc.patch.IToken) TTrue(de.be4.classicalb.core.parser.node.TTrue) TEqual(de.be4.classicalb.core.parser.node.TEqual) TRightPar(de.be4.classicalb.core.parser.node.TRightPar) TIdentifierLiteral(de.be4.classicalb.core.parser.node.TIdentifierLiteral) TLeftPar(de.be4.classicalb.core.parser.node.TLeftPar)

Example 8 with LexerException

use of de.be4.ltl.core.parser.lexer.LexerException in project probparsers by bendisposto.

the class EventBLexer method endStringToken.

private void endStringToken() throws LexerException {
    try {
        /*
			 * Push back current token. We are going to insert our own string
			 * token into the token stream just before the current token. Reset
			 * state so that unread token can be recognized again in next lexer
			 * step.
			 */
        unread(token);
        state = State.NORMAL;
        // create text for string token
        string.setText(createString());
    } catch (final IOException e) {
        throw new LexerException("IOException occured: " + e.getLocalizedMessage());
    }
    token = string;
    string = null;
    stringBuffer = null;
}
Also used : IOException(java.io.IOException) LexerException(de.be4.eventbalg.core.parser.lexer.LexerException)

Example 9 with LexerException

use of de.be4.ltl.core.parser.lexer.LexerException in project probparsers by bendisposto.

the class SatProblem method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
    final BParser parser = new BParser("testcase");
    Start ast = parser.eparse(testMachine, new Definitions());
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    final String string = ast2String.toString();
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Definitions(de.be4.classicalb.core.parser.Definitions) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Example 10 with LexerException

use of de.be4.ltl.core.parser.lexer.LexerException in project probparsers by bendisposto.

the class PredVarsTest method getTreeAsString.

private String getTreeAsString(final String testMachine) throws BCompoundException, LexerException, IOException {
    final BParser parser = new BParser("testcase");
    Start ast = parser.eparse(testMachine, new Definitions());
    final Ast2String ast2String = new Ast2String();
    ast.apply(ast2String);
    final String string = ast2String.toString();
    return string;
}
Also used : Start(de.be4.classicalb.core.parser.node.Start) Definitions(de.be4.classicalb.core.parser.Definitions) BParser(de.be4.classicalb.core.parser.BParser) Ast2String(util.Ast2String) Ast2String(util.Ast2String)

Aggregations

IOException (java.io.IOException)8 PushbackReader (java.io.PushbackReader)7 StringReader (java.io.StringReader)7 Start (de.be4.classicalb.core.parser.node.Start)5 BParser (de.be4.classicalb.core.parser.BParser)4 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)4 Reader (java.io.Reader)4 IToken (de.hhu.stups.sablecc.patch.IToken)3 Definitions (de.be4.classicalb.core.parser.Definitions)2 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)2 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)2 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 Token (de.be4.classicalb.core.parser.node.Token)2 ParserException (de.be4.classicalb.core.parser.parser.ParserException)2 Token (de.be4.classicalb.core.preparser.node.Token)2 LexerException (de.be4.eventb.core.parser.lexer.LexerException)2 LexerException (de.be4.eventbalg.core.parser.lexer.LexerException)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