Search in sources :

Example 6 with Token

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

the class PreParser method parse.

public void parse() throws PreParseException, IOException, BException, BCompoundException {
    final PreLexer preLexer = new PreLexer(pushbackReader);
    final Parser preParser = new Parser(preLexer);
    Start rootNode = null;
    try {
        rootNode = preParser.parse();
    } catch (final ParserException e) {
        if (e.getToken() instanceof de.be4.classicalb.core.preparser.node.TDefinitions) {
            final Token errorToken = e.getToken();
            final String message = "[" + errorToken.getLine() + "," + errorToken.getPos() + "] " + "Clause 'DEFINITIONS' is used more than once";
            throw new PreParseException(e.getToken(), message);
        } else {
            throw new PreParseException(e.getToken(), e.getLocalizedMessage());
        }
    } catch (final LexerException e) {
        throw new PreParseException(e.getLocalizedMessage());
    }
    final DefinitionPreCollector collector = new DefinitionPreCollector();
    rootNode.apply(collector);
    evaluateDefinitionFiles(collector.getFileDefinitions());
    List<Token> sortedDefinitionList = sortDefinitionsByTopologicalOrderAndCheckForCycles(collector.getDefinitions());
    evaluateTypes(sortedDefinitionList, collector.getDefinitions());
}
Also used : ParserException(de.be4.classicalb.core.preparser.parser.ParserException) Start(de.be4.classicalb.core.preparser.node.Start) Token(de.be4.classicalb.core.preparser.node.Token) DefinitionPreCollector(de.be4.classicalb.core.parser.analysis.checking.DefinitionPreCollector) Parser(de.be4.classicalb.core.preparser.parser.Parser) PreParseException(de.be4.classicalb.core.parser.exceptions.PreParseException) BLexerException(de.be4.classicalb.core.parser.exceptions.BLexerException) LexerException(de.be4.classicalb.core.preparser.lexer.LexerException)

Example 7 with Token

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

the class PrologExceptionPrinter method printBLexerException.

private static void printBLexerException(final IPrologTermOutput pto, final BLexerException e, final String filename, final boolean useIndentation, final boolean lineOneOff) {
    final Token token = e.getLastToken();
    final SourcePosition pos = token == null ? null : new SourcePosition(token.getLine(), token.getPos());
    printExceptionWithSourcePosition(pto, e, filename, pos, useIndentation, lineOneOff);
}
Also used : SourcePosition(de.hhu.stups.sablecc.patch.SourcePosition) Token(de.be4.classicalb.core.parser.node.Token)

Example 8 with Token

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

the class DefinitionsErrorsTest method checkForInvalidDefinition.

@Test
public void checkForInvalidDefinition() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEING x :=1 END \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid substitution 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,15]"));
        assertTrue(e.getMessage().contains("expecting end of definition"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 9 with Token

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

the class DefinitionsErrorsTest method checkForInvalidSubstitution.

@Test
public void checkForInvalidSubstitution() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEGIN\n x=1 END \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid substitution 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,3]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 10 with Token

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

the class DefinitionsErrorsTest method checkAtSymbolInDefinitions.

@Test
public void checkAtSymbolInDefinitions() throws Exception {
    String s = "MACHINE Definitions \n DEFINITIONS \n foo == BEGIN\n @ END \nEND";
    try {
        getTreeAsString(s);
        fail("Invalid substitution 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,2]"));
    }
}
Also used : Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

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