Search in sources :

Example 26 with Token

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

the class SyntaxErrorsDetectedOnTokenStreamTest method checkForDublicateAndInDefinitionsClause.

@Test
public void checkForDublicateAndInDefinitionsClause() throws Exception {
    String s = "MACHINE Definitions\nDEFINITIONS\n foo == 1=1 && 2=2  \nEND";
    try {
        getTreeAsString(s);
        fail("Duplicate & 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("[3,14]"));
        assertTrue(e.getMessage().contains("& &"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 27 with Token

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

the class StringLiteralNotClosedTest method testStringLiteralNotClosedShortString.

@Test
public void testStringLiteralNotClosedShortString() {
    final String testMachine = "MACHINE Test CONSTANTS the_string PROPERTIES the_string = \"not closed END";
    try {
        getTreeAsString(testMachine);
        fail("Exception did not occur");
    } catch (BCompoundException e) {
        assertEquals("[1,59] Unknown token: \"not closed END", e.getMessage());
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 28 with Token

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

the class UnitPragmaTest method testLexer.

@Test
public void testLexer() throws Exception {
    String input = "MACHINE UnitPragmaExpressions1 VARIABLES   lala, /*@ unit \"10**1 * m**1\" */ xx,   /*@ unit \"10**1 * m**1\" */ yy,   /*@ unit \"10**2 * m**2\" */ zz,   test  INVARIANT  /*@ label \"lol\" */  lala = \"trololo\" &xx:NAT &   yy:NAT &   zz:NAT &   test:NAT INITIALISATION xx,yy,zz,test:=1,2,3,4 OPERATIONS   multiply = zz := xx*yy;   add      = xx := yy+1;   sub      = xx := yy-1;   type     = test := yy 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 29 with Token

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

the class PragmaTest method testLexer.

@Test
public void testLexer() throws Exception {
    // String input = "/*@ generated */ MACHINE foo(x) \n"
    // + "/* look at me. */ \n"
    // + "DEFINITIONS \n"
    // + " /*@ conversion */ foo(m) == m \n"
    // + "PROPERTIES \n"
    // + "/*@ label foo */ \n"
    // + "/*@ label bar */ \n"
    // + "x = /*@ symbolic */ {y|->z| y < z } \n"
    // + "/*@ desc prop */ \n"
    // + "SETS A;B={a,b} /*@ desc trololo !!! */;C END";
    // String input =
    // "MACHINE foo PROPERTIES /*@ label foo */ x = /*@ symbolic */ {y|->z|
    // y < z } END";
    String input = "MACHINE foo CONSTANTS c /*@ desc konstante nummero uno */ PROPERTIES c = 5  VARIABLES x /*@ desc Hallo du variable */ INVARIANT x=1 INITIALISATION x:= 1 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();
    System.out.println("\n" + input);
    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) EOF(de.be4.classicalb.core.parser.node.EOF) PushbackReader(java.io.PushbackReader) Test(org.junit.Test)

Example 30 with Token

use of de.be4.ltl.core.ctlparser.node.Token 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.eventb.core.parser.lexer.LexerException)

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