Search in sources :

Example 66 with Node

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

the class StructuralTest method checkForMissingSemicolon.

@Test
public void checkForMissingSemicolon() throws Exception {
    String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip END\n  BAR= BEGIN r := xx END\nEND";
    try {
        getTreeAsString(s);
        fail("Missing Semicolon was not detected");
    } catch (BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        Node node = cause.getNodes()[0];
        assertEquals(4, node.getStartPos().getLine());
        assertEquals(3, node.getStartPos().getPos());
        assertTrue(e.getMessage().contains("Semicolon missing"));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Node(de.be4.classicalb.core.parser.node.Node) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 67 with Node

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

the class StructuralTest method checkForInvalidSemicolon.

@Test
public void checkForInvalidSemicolon() throws Exception {
    String s = "MACHINE MissingSemicolon\nOPERATIONS\n Foo=BEGIN skip END\n;\nEND";
    try {
        getTreeAsString(s);
        fail("Invalid Semicolon was not detected");
    } catch (BCompoundException e) {
        final CheckException cause = (CheckException) e.getCause();
        Node node = cause.getNodes()[0];
        System.out.println(cause.getMessage());
        assertEquals(4, node.getStartPos().getLine());
        assertEquals(1, node.getStartPos().getPos());
        assertTrue(e.getMessage().contains("Invalid semicolon after last operation"));
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) Node(de.be4.classicalb.core.parser.node.Node) Ast2String(util.Ast2String) BCompoundException(de.be4.classicalb.core.parser.exceptions.BCompoundException) Test(org.junit.Test)

Example 68 with Node

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

the class UnitPragmaTest method printAST.

private String printAST(final Node node) {
    final StringWriter swriter = new StringWriter();
    NodeIdAssignment nodeids = new NodeIdAssignment();
    node.apply(nodeids);
    IPrologTermOutput pout = new PrologTermOutput(new PrintWriter(swriter), false);
    PositionPrinter pprinter = new ClassicalPositionPrinter(nodeids);
    ASTProlog prolog = new ASTProlog(pout, pprinter);
    node.apply(prolog);
    swriter.flush();
    return swriter.toString();
}
Also used : ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) ASTProlog(de.be4.classicalb.core.parser.analysis.prolog.ASTProlog) StringWriter(java.io.StringWriter) PrologTermOutput(de.prob.prolog.output.PrologTermOutput) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.PositionPrinter) ClassicalPositionPrinter(de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter) NodeIdAssignment(de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment) IPrologTermOutput(de.prob.prolog.output.IPrologTermOutput) PrintWriter(java.io.PrintWriter)

Example 69 with Node

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

the class ReferencedMachines method caseAPackageParseUnit.

@Override
public void caseAPackageParseUnit(APackageParseUnit node) {
    determineRootDirectory(node.getPackage(), node);
    List<PImportPackage> copy = new ArrayList<>(node.getImports());
    for (PImportPackage e : copy) {
        e.apply(this);
    }
    node.getParseUnit().apply(this);
    // delete this node
    node.replaceBy(node.getParseUnit());
}
Also used : PImportPackage(de.be4.classicalb.core.parser.node.PImportPackage) ArrayList(java.util.ArrayList)

Example 70 with Node

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

the class ReferencedMachines method caseAMachineHeader.

@Override
public void caseAMachineHeader(AMachineHeader node) {
    machineName = Utils.getTIdentifierListAsString(node.getName());
    final String fileNameWithoutExtension = Utils.getFileWithoutExtension(mainFile.getName());
    if (isMachineNameMustMatchFileName && !machineName.equals(fileNameWithoutExtension)) {
        CheckException ch = new CheckException(String.format("Machine name does not match the file name: '%s' vs '%s'", machineName, fileNameWithoutExtension), node);
        throw new VisitorException(ch);
    }
}
Also used : CheckException(de.be4.classicalb.core.parser.exceptions.CheckException) TPragmaIdOrString(de.be4.classicalb.core.parser.node.TPragmaIdOrString) VisitorException(de.be4.classicalb.core.parser.exceptions.VisitorException)

Aggregations

CheckException (de.be4.classicalb.core.parser.exceptions.CheckException)42 PExpression (de.be4.classicalb.core.parser.node.PExpression)30 ArrayList (java.util.ArrayList)30 Node (de.be4.classicalb.core.parser.node.Node)20 AIdentifierExpression (de.be4.classicalb.core.parser.node.AIdentifierExpression)16 TIdentifierLiteral (de.be4.classicalb.core.parser.node.TIdentifierLiteral)12 TPragmaIdOrString (de.be4.classicalb.core.parser.node.TPragmaIdOrString)11 VisitorException (de.be4.classicalb.core.parser.exceptions.VisitorException)8 HashSet (java.util.HashSet)8 Token (de.be4.ltl.core.parser.node.Token)7 Type (de.be4.classicalb.core.parser.IDefinitions.Type)6 IOException (java.io.IOException)6 ASTProlog (de.be4.classicalb.core.parser.analysis.prolog.ASTProlog)5 PositionedNode (de.hhu.stups.sablecc.patch.PositionedNode)5 LinkedList (java.util.LinkedList)5 BCompoundException (de.be4.classicalb.core.parser.exceptions.BCompoundException)4 LinkedHashMap (java.util.LinkedHashMap)4 Test (org.junit.Test)4 ClassicalPositionPrinter (de.be4.classicalb.core.parser.analysis.prolog.ClassicalPositionPrinter)3 NodeIdAssignment (de.be4.classicalb.core.parser.analysis.prolog.NodeIdAssignment)3