Search in sources :

Example 6 with TComment

use of de.be4.eventbalg.core.parser.node.TComment 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)

Example 7 with TComment

use of de.be4.eventbalg.core.parser.node.TComment in project probparsers by bendisposto.

the class EventBParser method createEventBParseException.

private EventBParseException createEventBParseException(final ParserException e) {
    final Token token = e.getToken();
    String message = e.getMessage();
    final boolean expectingFound = message.indexOf("expecting") >= 0;
    /*
		 * Special error message for misplaced comments.
		 */
    if (expectingFound && token instanceof TComment) {
        message = MSG_COMMENT_PLACEMENT;
    }
    /*
		 * Replace some token names...
		 */
    message = message.replaceFirst(" at", " @");
    return new EventBParseException(token, message);
}
Also used : Token(de.be4.eventbalg.core.parser.node.Token) IToken(de.hhu.stups.sablecc.patch.IToken) TComment(de.be4.eventbalg.core.parser.node.TComment)

Example 8 with TComment

use of de.be4.eventbalg.core.parser.node.TComment 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 9 with TComment

use of de.be4.eventbalg.core.parser.node.TComment in project probparsers by bendisposto.

the class CommentTest method testMultiLineComment.

@Test
public void testMultiLineComment() throws Exception {
    final Start rootNode = parseInput("machine MultiLineComment invariants @inv1 asdf\n/* First line\n  Second line*/\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PInvariant> invariants = parseUnit.getInvariants();
    final AInvariant invariant = (AInvariant) invariants.get(0);
    // correct comment content?
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    final StringTokenizer tokenizer = new StringTokenizer(comments.get(0).getText(), "\n\r");
    assertEquals(2, tokenizer.countTokens());
    assertEquals("First line", tokenizer.nextToken());
    assertEquals("  Second line", tokenizer.nextToken());
    // correct invariant label?
    assertEquals("inv1", invariant.getName().getText());
    // correct string representation for predicate?
    assertEquals("asdf", invariant.getPredicate().getText());
}
Also used : StringTokenizer(java.util.StringTokenizer) 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 10 with TComment

use of de.be4.eventbalg.core.parser.node.TComment in project probparsers by bendisposto.

the class CommentTest method testCommentPredicates2.

@Test
public void testCommentPredicates2() throws Exception {
    final Start rootNode = parseInput("machine CommentPredicates2 invariants\n @inv0 asdf\n @inv1 asdf\n//MyComment\nend", 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("inv0", invariant.getName().getText());
    assertEquals("asdf", invariant.getPredicate().getText());
    // correct comment content, i.e., is whitespace in the beginning
    // omitted?
    invariant = (AInvariant) invariants.get(1);
    final LinkedList<TComment> comments = invariant.getComments();
    assertEquals(1, comments.size());
    assertEquals("MyComment", comments.get(0).getText());
    assertEquals("inv1", invariant.getName().getText());
    assertEquals("asdf", 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)

Aggregations

Test (org.junit.Test)12 TComment (de.be4.eventb.core.parser.node.TComment)8 TComment (de.be4.eventbalg.core.parser.node.TComment)8 AMachineParseUnit (de.be4.eventb.core.parser.node.AMachineParseUnit)6 Start (de.be4.eventb.core.parser.node.Start)6 AMachineParseUnit (de.be4.eventbalg.core.parser.node.AMachineParseUnit)6 Start (de.be4.eventbalg.core.parser.node.Start)6 StringTokenizer (java.util.StringTokenizer)4 AInvariant (de.be4.eventb.core.parser.node.AInvariant)3 PInvariant (de.be4.eventb.core.parser.node.PInvariant)3 AInvariant (de.be4.eventbalg.core.parser.node.AInvariant)3 PInvariant (de.be4.eventbalg.core.parser.node.PInvariant)3 IToken (de.hhu.stups.sablecc.patch.IToken)2 AVariable (de.be4.eventb.core.parser.node.AVariable)1 EOF (de.be4.eventb.core.parser.node.EOF)1 PVariable (de.be4.eventb.core.parser.node.PVariable)1 TMultiCommentEnd (de.be4.eventb.core.parser.node.TMultiCommentEnd)1 Token (de.be4.eventb.core.parser.node.Token)1 AVariable (de.be4.eventbalg.core.parser.node.AVariable)1 EOF (de.be4.eventbalg.core.parser.node.EOF)1