Search in sources :

Example 16 with Token

use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.

the class PrologGenerator method caseAActionLtl.

@Override
public void caseAActionLtl(final AActionLtl node) {
    final Token token = node.getOperation();
    p.openTerm("action");
    helper.parseTransitionPredicate(UniversalToken.createToken(token));
    p.closeTerm();
}
Also used : Token(de.be4.ltl.core.parser.node.Token)

Example 17 with Token

use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.

the class PrologGenerator method caseAUnparsedLtl.

@Override
public void caseAUnparsedLtl(final AUnparsedLtl node) {
    final Token token = node.getPredicate();
    helper.caseUnparsed(UniversalToken.createToken(token));
}
Also used : Token(de.be4.ltl.core.parser.node.Token)

Example 18 with Token

use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.

the class StringLiteralNotClosedTest method testStringLiteralNotClosedLongString.

@Test
public void testStringLiteralNotClosedLongString() {
    final String testMachine = "MACHINE Test CONSTANTS the_string PROPERTIES the_string = \"not closed" + randomString(100) + "END";
    try {
        getTreeAsString(testMachine);
        fail("Exception did not occur");
    } catch (BCompoundException e) {
        System.out.println(e.getCause());
        assertTrue(e.getCause() instanceof PreParseException);
        assertTrue(e.getLocalizedMessage().contains("Unknown token:"));
    }
}
Also used : Ast2String(util.Ast2String) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 19 with Token

use of de.be4.classicalb.core.parser.node.Token in project probparsers by bendisposto.

the class UnitPragmaTest method testUnitAlias.

@Test
public void testUnitAlias() throws Exception {
    String input = "/*@ unit_alias kmph \"km/h\" */ MACHINE UnitAlias VARIABLES lala INVARIANT lala=0 INITIALISATION lala:=0 END";
    BLexer lex = new BLexer(new PushbackReader(new StringReader(input), 500));
    Token t;
    while (!((t = lex.next()) instanceof EOF)) {
        System.out.print(t.getClass().getSimpleName() + "(" + t.getText() + ")");
        System.out.print(" ");
    }
    BParser p = new BParser();
    Start ast = p.parse(input, false);
    ASTPrinter pr = new ASTPrinter();
    ast.apply(pr);
    System.out.println(printAST(ast));
}
Also used : BLexer(de.be4.classicalb.core.parser.BLexer) Start(de.be4.classicalb.core.parser.node.Start) ASTPrinter(de.be4.classicalb.core.parser.visualisation.ASTPrinter) StringReader(java.io.StringReader) Token(de.be4.classicalb.core.parser.node.Token) BParser(de.be4.classicalb.core.parser.BParser) Helpers.getTreeAsString(util.Helpers.getTreeAsString) EOF(de.be4.classicalb.core.parser.node.EOF) PushbackReader(java.io.PushbackReader) Test(org.junit.Test)

Example 20 with Token

use of de.be4.classicalb.core.parser.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.eventb.core.parser.node.TMultiCommentEnd) TComment(de.be4.eventb.core.parser.node.TComment) EOF(de.be4.eventb.core.parser.node.EOF)

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