Search in sources :

Example 36 with BException

use of de.be4.classicalb.core.parser.exceptions.BException in project probparsers by bendisposto.

the class CommentTest method testInvariantsAndMultiComments.

@Test
public void testInvariantsAndMultiComments() throws BException {
    final String input = "machine InvariantsAndMultiComments invariants\n" + "@inv1 1=1\n" + "@inv2 2=2\n" + "/*inv2\ncomment*/\n" + "end";
    final Start rootNode = parseInput(input, false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    assertEquals(2, invariants.size());
    AInvariant invariant = (AInvariant) invariants.get(0);
    assertEquals(0, invariant.getComments().size());
    assertEquals("inv1", invariant.getName().getText());
    assertEquals("1=1", invariant.getPredicate().getText());
    invariant = (AInvariant) invariants.get(1);
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    assertEquals("inv2\ncomment", comments.get(0).getText());
    assertEquals("inv2", invariant.getName().getText());
    assertEquals("2=2", invariant.getPredicate().getText());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) PInvariant(de.be4.eventbalg.core.parser.node.PInvariant) AInvariant(de.be4.eventbalg.core.parser.node.AInvariant) TComment(de.be4.eventbalg.core.parser.node.TComment) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 37 with BException

use of de.be4.classicalb.core.parser.exceptions.BException in project probparsers by bendisposto.

the class EventBParser method main.

public static void main(final String[] args) {
    if (args.length < 1) {
        System.err.println("usage: BParser [options] <BMachine file>");
        System.err.println();
        System.err.println("Available options are:");
        System.err.println(CLI_SWITCH_VERBOSE + "\t\tVerbose output during lexing and parsing");
        System.err.println(CLI_SWITCH_TIME + "\t\tOutput time used for complete parsing process.");
        System.err.println(CLI_SWITCH_AST + "\t\tPrint AST on standard output.");
        System.err.println(CLI_SWITCH_UI + "\t\tShow AST as Swing UI.");
        System.exit(-1);
    }
    try {
        final long start = System.currentTimeMillis();
        final EventBParser parser = new EventBParser();
        final Start tree = parser.parseFile(new File(args[args.length - 1]), isCliSwitchSet(args, CLI_SWITCH_VERBOSE));
        final long end = System.currentTimeMillis();
        System.out.println();
        if (isCliSwitchSet(args, CLI_SWITCH_TIME)) {
            System.out.println("Time for parsing: " + (end - start) + "ms");
        }
        if (isCliSwitchSet(args, CLI_SWITCH_AST)) {
            System.out.println("AST:");
            tree.apply(new ASTPrinter());
        }
        if (isCliSwitchSet(args, CLI_SWITCH_UI)) {
            tree.apply(new ASTDisplay());
        }
    } catch (final IOException e) {
        System.err.println();
        System.err.println("Error reading input file: " + e.getLocalizedMessage());
        System.exit(-2);
    } catch (final BException e) {
        System.err.println();
        System.err.println("Error parsing input file: " + e.getLocalizedMessage());
        System.exit(-3);
    }
}
Also used : Start(de.be4.eventb.core.parser.node.Start) ASTPrinter(de.be4.eventb.core.parser.analysis.ASTPrinter) ASTDisplay(de.be4.eventb.core.parser.analysis.ASTDisplay) IOException(java.io.IOException) File(java.io.File)

Example 38 with BException

use of de.be4.classicalb.core.parser.exceptions.BException in project probparsers by bendisposto.

the class CommentTest method testInvariantsAndMultiComments.

@Test
public void testInvariantsAndMultiComments() throws BException {
    final String input = "machine InvariantsAndMultiComments invariants\n" + "@inv1 1=1\n" + "@inv2 2=2\n" + "/*inv2\ncomment*/\n" + "end";
    final Start rootNode = parseInput(input, false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    assertEquals(2, invariants.size());
    AInvariant invariant = (AInvariant) invariants.get(0);
    assertEquals(0, invariant.getComments().size());
    assertEquals("inv1", invariant.getName().getText());
    assertEquals("1=1", invariant.getPredicate().getText());
    invariant = (AInvariant) invariants.get(1);
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    assertEquals("inv2\ncomment", comments.get(0).getText());
    assertEquals("inv2", invariant.getName().getText());
    assertEquals("2=2", invariant.getPredicate().getText());
}
Also used : Start(de.be4.eventb.core.parser.node.Start) PInvariant(de.be4.eventb.core.parser.node.PInvariant) AInvariant(de.be4.eventb.core.parser.node.AInvariant) TComment(de.be4.eventb.core.parser.node.TComment) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Aggregations

BException (de.be4.classicalb.core.parser.exceptions.BException)22 CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)15 IOException (java.io.IOException)9 ArrayList (java.util.ArrayList)9 Start (de.be4.eventbalg.core.parser.node.Start)7 Test (org.junit.Test)7 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)6 Start (de.be4.eventb.core.parser.node.Start)6 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)4 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)4 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)3 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)3 PrettyPrinter (de.be4.classicalb.core.parser.util.PrettyPrinter)3 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)3 File (java.io.File)3 ParsingBehaviour (de.be4.classicalb.core.parser.ParsingBehaviour)2 BParseException (de.be4.classicalb.core.parser.exceptions.BParseException)2 Token (de.be4.classicalb.core.preparser.node.Token)2 AInvariant (de.be4.eventb.core.parser.node.AInvariant)2