Search in sources :

Example 1 with TComment

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

the class CommentTest method testMultipleComments1.

@Test
public void testMultipleComments1() throws Exception {
    final Start rootNode = parseInput("machine MultipleComments1" + "// line1\n" + "/* line2\nline3*/" + "// line4\n" + "\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<TComment> comments = parseUnit.getComments();
    assertEquals(3, comments.size());
    assertEquals("line1", comments.get(0).getText());
    assertEquals("line2\nline3", comments.get(1).getText());
    assertEquals("line4", comments.get(2).getText());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) TComment(de.be4.eventbalg.core.parser.node.TComment) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 2 with TComment

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

the class CommentTest method testCommentVariables1.

@Test
public void testCommentVariables1() throws Exception {
    final Start rootNode = parseInput("machine CommentVariables1 variables\n" + "varA" + "//varA comment\n" + " varB\n" + "varC\n" + "/*varC\ncomment*/" + "end", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PVariable> variables = parseUnit.getVariables();
    assertEquals(3, variables.size());
    AVariable variable = (AVariable) variables.get(0);
    assertEquals("varA", variable.getName().getText());
    assertEquals("varA comment", variable.getComments().get(0).getText());
    variable = (AVariable) variables.get(1);
    assertEquals("varB", variable.getName().getText());
    assertEquals(0, variable.getComments().size());
    variable = (AVariable) variables.get(2);
    assertEquals("varC", variable.getName().getText());
    final LinkedList<TComment> comments = variable.getComments();
    assertNotNull(comments);
    assertEquals(1, comments.size());
    final StringTokenizer tokenizer = new StringTokenizer(comments.get(0).getText(), "\n\r");
    assertEquals(2, tokenizer.countTokens());
    assertEquals("varC", tokenizer.nextToken());
    assertEquals("comment", tokenizer.nextToken());
}
Also used : AVariable(de.be4.eventbalg.core.parser.node.AVariable) StringTokenizer(java.util.StringTokenizer) Start(de.be4.eventbalg.core.parser.node.Start) TComment(de.be4.eventbalg.core.parser.node.TComment) PVariable(de.be4.eventbalg.core.parser.node.PVariable) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 3 with TComment

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

the class CommentTest method testMultipleComments2.

@Test
public void testMultipleComments2() throws Exception {
    final Start rootNode = parseInput("machine MultipleComments2" + "/* line1*/\n" + "/* line2\nline3*/" + "// line4\n" + "\nend", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<TComment> comments = parseUnit.getComments();
    assertEquals(3, comments.size());
    assertEquals("line1", comments.get(0).getText());
    assertEquals("line2\nline3", comments.get(1).getText());
    assertEquals("line4", comments.get(2).getText());
}
Also used : Start(de.be4.eventbalg.core.parser.node.Start) TComment(de.be4.eventbalg.core.parser.node.TComment) AMachineParseUnit(de.be4.eventbalg.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 4 with TComment

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

the class CommentTest method testCommentVariables1.

@Test
public void testCommentVariables1() throws Exception {
    final Start rootNode = parseInput("machine CommentVariables1 variables\n" + "varA" + "//varA comment\n" + " varB\n" + "varC\n" + "/*varC\ncomment*/" + "end", false);
    final AMachineParseUnit parseUnit = (AMachineParseUnit) rootNode.getPParseUnit();
    final LinkedList<PVariable> variables = parseUnit.getVariables();
    assertEquals(3, variables.size());
    AVariable variable = (AVariable) variables.get(0);
    assertEquals("varA", variable.getName().getText());
    assertEquals("varA comment", variable.getComments().get(0).getText());
    variable = (AVariable) variables.get(1);
    assertEquals("varB", variable.getName().getText());
    assertEquals(0, variable.getComments().size());
    variable = (AVariable) variables.get(2);
    assertEquals("varC", variable.getName().getText());
    final LinkedList<TComment> comments = variable.getComments();
    assertNotNull(comments);
    assertEquals(1, comments.size());
    final StringTokenizer tokenizer = new StringTokenizer(comments.get(0).getText(), "\n\r");
    assertEquals(2, tokenizer.countTokens());
    assertEquals("varC", tokenizer.nextToken());
    assertEquals("comment", tokenizer.nextToken());
}
Also used : AVariable(de.be4.eventb.core.parser.node.AVariable) StringTokenizer(java.util.StringTokenizer) Start(de.be4.eventb.core.parser.node.Start) TComment(de.be4.eventb.core.parser.node.TComment) PVariable(de.be4.eventb.core.parser.node.PVariable) AMachineParseUnit(de.be4.eventb.core.parser.node.AMachineParseUnit) Test(org.junit.Test)

Example 5 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.eventbalg.core.parser.node.TMultiCommentEnd) TComment(de.be4.eventbalg.core.parser.node.TComment) EOF(de.be4.eventbalg.core.parser.node.EOF)

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