Search in sources :

Example 11 with Token

use of de.be4.ltl.core.ctlparser.node.Token in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidFormula.

@Test
public void checkForInvalidFormula() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n 1+; \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid formula was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[4,4]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 12 with Token

use of de.be4.ltl.core.ctlparser.node.Token in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidFormula3.

@Test
public void checkForInvalidFormula3() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo(xx) == (xx : OBJECTS -->(1..card(OBJECTS))\n; \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid formula was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[4,1]"));
        assertTrue(e.getMessage().contains("expecting: ')'"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 13 with Token

use of de.be4.ltl.core.ctlparser.node.Token in project probparsers by bendisposto.

the class DefinitionsErrorsTest method checkForInvalidFormula2.

@Test
public void checkForInvalidFormula2() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS\n foo == \n 1=; \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid formula was not detected.");
    } catch (BCompoundException e) {
        System.out.println(e.getMessage());
        // there is no token available, hence the position is in the text
        assertTrue(e.getMessage().contains("[4,4]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 14 with Token

use of de.be4.ltl.core.ctlparser.node.Token in project probparsers by bendisposto.

the class EventBLexer method collectMultiLineComment.

private void collectMultiLineComment() throws EventBLexerException {
    if (state.equals(State.MULTI_COMMENT)) {
        if (token instanceof EOF) {
            // tokenList.add(token);
            throw new EventBLexerException(token, "Comment not closed");
        }
        /*
			 * Starting a new multiline comment, so first token is
			 * TMultiCommentStart
			 */
        if (commentStart == null) {
            commentStart = (TMultiCommentStart) token;
            commentBuffer = new StringBuilder();
            token = null;
        } else {
            // end of comment reached?
            if (token instanceof TMultiCommentEnd) {
                token = new TComment(commentBuffer.toString(), commentStart.getLine(), commentStart.getPos());
                commentStart = null;
                commentBuffer = null;
                state = State.NORMAL;
            } else {
                commentBuffer.append(token.getText());
                token = null;
            }
        }
    }
}
Also used : TMultiCommentEnd(de.be4.eventbalg.core.parser.node.TMultiCommentEnd) TComment(de.be4.eventbalg.core.parser.node.TComment) EOF(de.be4.eventbalg.core.parser.node.EOF)

Example 15 with Token

use of de.be4.ltl.core.ctlparser.node.Token in project probparsers by bendisposto.

the class CtlParser method parseFormula.

protected Start parseFormula(final String formula) throws LtlParseException, IOException {
    StringReader reader = new StringReader(formula);
    PushbackReader r = new PushbackReader(reader);
    Lexer l = new CtlLexer(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.ctlparser.parser.ParserException) CtlLexer(de.be4.ltl.core.parser.internal.CtlLexer) Lexer(de.be4.ltl.core.ctlparser.lexer.Lexer) UniversalToken(de.be4.ltl.core.parser.internal.UniversalToken) Start(de.be4.ltl.core.ctlparser.node.Start) StringReader(java.io.StringReader) CtlLexer(de.be4.ltl.core.parser.internal.CtlLexer) LexerException(de.be4.ltl.core.ctlparser.lexer.LexerException) PushbackReader(java.io.PushbackReader) Parser(de.be4.ltl.core.ctlparser.parser.Parser)

Aggregations

Test (org.junit.Test)13 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)10 IOException (java.io.IOException)10 PushbackReader (java.io.PushbackReader)10 StringReader (java.io.StringReader)10 Ast2String (util.Ast2String)10 Token (de.be4.classicalb.core.parser.node.Token)8 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)7 Token (de.be4.classicalb.core.preparser.node.Token)7 Token (de.be4.ltl.core.parser.node.Token)7 EOF (de.be4.classicalb.core.parser.node.EOF)5 Start (de.be4.classicalb.core.parser.node.Start)5 IToken (de.hhu.stups.sablecc.patch.IToken)5 Reader (java.io.Reader)5 ArrayList (java.util.ArrayList)4 BLexer (de.be4.classicalb.core.parser.BLexer)3 BParser (de.be4.classicalb.core.parser.BParser)3 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)3