Search in sources :

Example 1 with EOF

use of de.be4.classicalb.core.parser.node.EOF in project probparsers by bendisposto.

the class CreateFreetypeTest method createMachine.

private Start createMachine(String name) {
    final AFreetypesMachineClause freetypes = createFreetype();
    final AConstantsMachineClause variables = new AConstantsMachineClause(createIdentifiers(VAR_NAME));
    final AMemberPredicate member = new AMemberPredicate(createIdentifier(VAR_NAME), new APowSubsetExpression(createIdentifier(FREETYPE_NAME)));
    final AInvariantMachineClause inv = new AInvariantMachineClause(member);
    final AInitialisationMachineClause init = new AInitialisationMachineClause(createAssignment(VAR_NAME, new AEmptySetExpression()));
    final AOperationsMachineClause operations = createOperations();
    final AMachineHeader header = new AMachineHeader(createIdLits(name), EMPTY_EXPRS);
    final AAbstractMachineParseUnit machine = new AAbstractMachineParseUnit(new AMachineMachineVariant(), header, Arrays.asList(freetypes, variables, inv, init, operations));
    return new Start(machine, new EOF());
}
Also used : AMachineMachineVariant(de.be4.classicalb.core.parser.node.AMachineMachineVariant) AInitialisationMachineClause(de.be4.classicalb.core.parser.node.AInitialisationMachineClause) AMachineHeader(de.be4.classicalb.core.parser.node.AMachineHeader) AConstantsMachineClause(de.be4.classicalb.core.parser.node.AConstantsMachineClause) Start(de.be4.classicalb.core.parser.node.Start) AMemberPredicate(de.be4.classicalb.core.parser.node.AMemberPredicate) AAbstractMachineParseUnit(de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit) AOperationsMachineClause(de.be4.classicalb.core.parser.node.AOperationsMachineClause) AInvariantMachineClause(de.be4.classicalb.core.parser.node.AInvariantMachineClause) AFreetypesMachineClause(de.be4.classicalb.core.parser.node.AFreetypesMachineClause) APowSubsetExpression(de.be4.classicalb.core.parser.node.APowSubsetExpression) AEmptySetExpression(de.be4.classicalb.core.parser.node.AEmptySetExpression) EOF(de.be4.classicalb.core.parser.node.EOF)

Example 2 with EOF

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

Example 3 with EOF

use of de.be4.classicalb.core.parser.node.EOF in project probparsers by bendisposto.

the class UnitPragmaTest method testUnitAlias.

@Test
public void testUnitAlias() throws Exception {
    String input = "/*@ unit_alias kmph \"km/h\" */ MACHINE UnitAlias VARIABLES lala INVARIANT lala=0 INITIALISATION lala:=0 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 4 with EOF

use of de.be4.classicalb.core.parser.node.EOF 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 5 with EOF

use of de.be4.classicalb.core.parser.node.EOF in project prob2 by bendisposto.

the class DomBuilder method createExpressionAST.

private Start createExpressionAST(final PExpression expression) {
    Start start = new Start();
    AExpressionParseUnit node = new AExpressionParseUnit();
    start.setPParseUnit(node);
    start.setEOF(EOF);
    node.setExpression((PExpression) expression.clone());
    node.getExpression().apply(new RenameIdentifiers());
    return start;
}
Also used : AExpressionParseUnit(de.be4.classicalb.core.parser.node.AExpressionParseUnit) Start(de.be4.classicalb.core.parser.node.Start)

Aggregations

Start (de.be4.classicalb.core.parser.node.Start)8 EOF (de.be4.classicalb.core.parser.node.EOF)6 PushbackReader (java.io.PushbackReader)5 StringReader (java.io.StringReader)5 Token (de.be4.classicalb.core.parser.node.Token)4 BLexer (de.be4.classicalb.core.parser.BLexer)3 BParser (de.be4.classicalb.core.parser.BParser)3 ASTPrinter (de.be4.classicalb.core.parser.visualisation.ASTPrinter)3 Test (org.junit.Test)3 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)2 IOException (java.io.IOException)2 Reader (java.io.Reader)2 Helpers.getTreeAsString (util.Helpers.getTreeAsString)2 BLexerException (de.be4.classicalb.core.parser.exceptions.BLexerException)1 PreParseException (de.be4.classicalb.core.parser.exceptions.PreParseException)1 LexerException (de.be4.classicalb.core.parser.lexer.LexerException)1 AAbstractMachineParseUnit (de.be4.classicalb.core.parser.node.AAbstractMachineParseUnit)1 AConstantsMachineClause (de.be4.classicalb.core.parser.node.AConstantsMachineClause)1 AEmptySetExpression (de.be4.classicalb.core.parser.node.AEmptySetExpression)1 AExpressionParseUnit (de.be4.classicalb.core.parser.node.AExpressionParseUnit)1