Commit 08f697b5 authored by Sarah Grebing's avatar Sarah Grebing

closes expression in parser

parent c951d29c
Pipeline #13169 failed with stage
in 44 seconds
...@@ -114,17 +114,13 @@ casesStmt ...@@ -114,17 +114,13 @@ casesStmt
; ;
casesList casesList
// : simpleCase : CASE (TRY | expression | closesExpression) COLON? INDENT stmtList DEDENT
// | closableCase
: CASE (ISCLOSED | expression) COLON? INDENT stmtList DEDENT
; ;
/*simpleCase
: CASE expression COLON? INDENT stmtList DEDENT closesExpression
; : CLOSES closesScript= scriptCommand
closableCase
: CASE MATCH ISCLOSED COLON? INDENT stmtList DEDENT
; ;
*/
forEachStmt forEachStmt
: FOREACH INDENT stmtList DEDENT : FOREACH INDENT stmtList DEDENT
; ;
...@@ -133,6 +129,7 @@ theOnlyStmt ...@@ -133,6 +129,7 @@ theOnlyStmt
: THEONLY INDENT stmtList DEDENT : THEONLY INDENT stmtList DEDENT
; ;
scriptCommand scriptCommand
: cmd=ID parameters? SEMICOLON : cmd=ID parameters? SEMICOLON
; ;
...@@ -155,7 +152,8 @@ MULTI_LINE_COMMENT : '/*' (MULTI_LINE_COMMENT|.)*? '*/' -> channel(HIDDEN); ...@@ -155,7 +152,8 @@ MULTI_LINE_COMMENT : '/*' (MULTI_LINE_COMMENT|.)*? '*/' -> channel(HIDDEN);
CASES: 'cases'; CASES: 'cases';
CASE: 'case'; CASE: 'case';
ISCLOSED: 'isCloseable'; TRY: 'try';
CLOSES: 'closes';
DERIVABLE : 'derivable'; DERIVABLE : 'derivable';
DEFAULT: 'default'; DEFAULT: 'default';
ASSIGN : ':='; ASSIGN : ':=';
......
...@@ -23,8 +23,9 @@ package edu.kit.iti.formal.psdbg.parser; ...@@ -23,8 +23,9 @@ package edu.kit.iti.formal.psdbg.parser;
*/ */
import edu.kit.iti.formal.psdbg.parser.types.Type;
import edu.kit.iti.formal.psdbg.parser.ast.*; import edu.kit.iti.formal.psdbg.parser.ast.*;
import edu.kit.iti.formal.psdbg.parser.types.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
...@@ -111,9 +112,9 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> { ...@@ -111,9 +112,9 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> {
} }
@Override @Override
public IsClosableCase visit(IsClosableCase isClosableCase) { public tryCase visit(tryCase tryCase) {
isClosableCase.getBody().accept(this); tryCase.getBody().accept(this);
return isClosableCase; return tryCase;
} }
@Override @Override
...@@ -123,6 +124,13 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> { ...@@ -123,6 +124,13 @@ public class ASTChanger extends DefaultASTVisitor<ASTNode> {
return simpleCaseStatement; return simpleCaseStatement;
} }
@Override
public ASTNode visit(ClosesCase closesCase) {
closesCase.getClosesScript().accept(this);
closesCase.getBody().accept(this);
return closesCase;
}
@Override @Override
public CaseStatement visit(CaseStatement caseStatement) { public CaseStatement visit(CaseStatement caseStatement) {
//caseStatement.getGuard().accept(this); //caseStatement.getGuard().accept(this);
......
...@@ -161,8 +161,8 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -161,8 +161,8 @@ public interface ASTTraversal<T> extends Visitor<T> {
} }
@Override @Override
default T visit(IsClosableCase isClosableCase) { default T visit(tryCase tryCase) {
isClosableCase.getBody().accept(this); tryCase.getBody().accept(this);
return null; return null;
} }
...@@ -181,4 +181,11 @@ public interface ASTTraversal<T> extends Visitor<T> { ...@@ -181,4 +181,11 @@ public interface ASTTraversal<T> extends Visitor<T> {
} }
return null; return null;
} }
@Override
default T visit(ClosesCase closesCase) {
closesCase.getClosesScript().accept(this);
closesCase.getBody().accept(this);
return null;
}
} }
...@@ -133,8 +133,8 @@ public class DefaultASTVisitor<T> implements Visitor<T> { ...@@ -133,8 +133,8 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
} }
@Override @Override
public T visit(IsClosableCase isClosableCase) { public T visit(tryCase tryCase) {
return defaultVisit(isClosableCase); return defaultVisit(tryCase);
} }
@Override @Override
...@@ -142,5 +142,9 @@ public class DefaultASTVisitor<T> implements Visitor<T> { ...@@ -142,5 +142,9 @@ public class DefaultASTVisitor<T> implements Visitor<T> {
return defaultVisit(simpleCaseStatement); return defaultVisit(simpleCaseStatement);
} }
@Override
public T visit(ClosesCase closesCase) {
return defaultVisit(closesCase);
}
} }
...@@ -23,6 +23,7 @@ package edu.kit.iti.formal.psdbg.parser; ...@@ -23,6 +23,7 @@ package edu.kit.iti.formal.psdbg.parser;
*/ */
import edu.kit.iti.formal.psdbg.parser.ast.*;
import edu.kit.iti.formal.psdbg.parser.types.TypeFacade; import edu.kit.iti.formal.psdbg.parser.types.TypeFacade;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ErrorNode; import org.antlr.v4.runtime.tree.ErrorNode;
...@@ -34,7 +35,6 @@ import java.util.ArrayList; ...@@ -34,7 +35,6 @@ import java.util.ArrayList;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import edu.kit.iti.formal.psdbg.parser.ast.*;
/** /**
* @author Alexander Weigl * @author Alexander Weigl
...@@ -318,11 +318,20 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -318,11 +318,20 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
@Override @Override
public Object visitCasesList(ScriptLanguageParser.CasesListContext ctx) { public Object visitCasesList(ScriptLanguageParser.CasesListContext ctx) {
if (ctx.ISCLOSED() != null) { if (ctx.TRY() != null) {
IsClosableCase isClosableCase = new IsClosableCase(); tryCase tryCase = new tryCase();
isClosableCase.setRuleContext(ctx); tryCase.setRuleContext(ctx);
isClosableCase.setBody((Statements) ctx.stmtList().accept(this)); tryCase.setBody((Statements) ctx.stmtList().accept(this));
return isClosableCase; return tryCase;
}
if (ctx.closesExpression() != null) {
ClosesCase closesCase = new ClosesCase();
closesCase.setClosedStmt(true);
closesCase.setRuleContext(ctx);
closesCase.setClosesScript((CallStatement) ctx.closesExpression().closesScript.accept(this));
closesCase.setBody((Statements) ctx.stmtList().accept(this));
return closesCase;
} else { } else {
SimpleCaseStatement caseStatement = new SimpleCaseStatement(); SimpleCaseStatement caseStatement = new SimpleCaseStatement();
caseStatement.setRuleContext(ctx); caseStatement.setRuleContext(ctx);
...@@ -338,6 +347,11 @@ public class TransformAst implements ScriptLanguageVisitor<Object> { ...@@ -338,6 +347,11 @@ public class TransformAst implements ScriptLanguageVisitor<Object> {
} }
@Override
public Object visitClosesExpression(ScriptLanguageParser.ClosesExpressionContext ctx) {
return null;
}
/* /*
@Override @Override
public Object visitSimpleCase(ScriptLanguageParser.SimpleCaseContext ctx) { public Object visitSimpleCase(ScriptLanguageParser.SimpleCaseContext ctx) {
......
...@@ -68,11 +68,13 @@ public interface Visitor<T> { ...@@ -68,11 +68,13 @@ public interface Visitor<T> {
T visit(UnaryExpression e); T visit(UnaryExpression e);
T visit(IsClosableCase isClosableCase); T visit(tryCase tryCase);
T visit(SimpleCaseStatement simpleCaseStatement); T visit(SimpleCaseStatement simpleCaseStatement);
T visit(CaseStatement caseStatement); T visit(CaseStatement caseStatement);
T visit(SubstituteExpression subst); T visit(SubstituteExpression subst);
T visit(ClosesCase colsesCase);
} }
package edu.kit.iti.formal.psdbg.parser.ast;
import edu.kit.iti.formal.psdbg.parser.Visitor;
import lombok.Data;
import lombok.NoArgsConstructor;
/**
* Object representing a "closes closeScriptCall(): { Commands}" block in a cases
*/
@Data
@NoArgsConstructor
public class ClosesCase extends CaseStatement {
private boolean isClosedStmt = true;
/**
* Script that should be executed and shown whether case can be closed
*/
private CallStatement closesScript;
/**
* A close subscript() {bodyscript} expression
*
* @param closesScript the script that is exectued in order to determine whether goal would clos. This proof is pruned afterwards
* @param body the actual script that is then executed when closesscript was successful and pruned
*/
public ClosesCase(CallStatement closesScript, Statements body) {
this.body = body;
this.closesScript = closesScript;
}
/**
* {@inheritDoc}
*/
@Override
public <T> T accept(Visitor<T> visitor) {
return visitor.visit(this);
}
/**
* {@inheritDoc}
*/
@Override
public tryCase copy() {
return new tryCase(body.copy());
}
}
...@@ -5,14 +5,14 @@ import lombok.Data; ...@@ -5,14 +5,14 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
/** /**
* Object representing a "match isClosable{ Commands}" block * Object representing a "try { Commands}" block in a cases
*/ */
@Data @Data
@NoArgsConstructor @NoArgsConstructor
public class IsClosableCase extends CaseStatement { public class tryCase extends CaseStatement {
private boolean isClosedStmt = true; private boolean isClosedStmt = true;
public IsClosableCase(Statements body) { public tryCase(Statements body) {
this.body = body; this.body = body;
} }
...@@ -28,7 +28,7 @@ public class IsClosableCase extends CaseStatement { ...@@ -28,7 +28,7 @@ public class IsClosableCase extends CaseStatement {
* {@inheritDoc} * {@inheritDoc}
*/ */
@Override @Override
public IsClosableCase copy() { public tryCase copy() {
return new IsClosableCase(body.copy()); return new tryCase(body.copy());
} }
} }
script ruRg ()
{ cases
{ case abc :
{ aM:TERM:=not ka&bi;
dsL f5=90;
}
case try :
{ last;
}
case closes body;{
last;
last;
}
}
}
script body()
{
foo;
}
\ No newline at end of file
...@@ -57,7 +57,7 @@ ...@@ -57,7 +57,7 @@
<module>rt</module> <module>rt</module>
<module>rt-key</module> <module>rt-key</module>
<module>ui</module> <module>ui</module>
<module>DockFX</module> <module>lib/DockFX</module>
<module>lint</module> <module>lint</module>
<module>keydeps</module> <module>keydeps</module>
<module>matcher</module> <module>matcher</module>
......
...@@ -11,7 +11,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.KeyData; ...@@ -11,7 +11,7 @@ import edu.kit.iti.formal.psdbg.interpreter.data.KeyData;
import edu.kit.iti.formal.psdbg.interpreter.data.State; import edu.kit.iti.formal.psdbg.interpreter.data.State;
import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment; import edu.kit.iti.formal.psdbg.interpreter.data.VariableAssignment;
import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandLookup; import edu.kit.iti.formal.psdbg.interpreter.funchdl.CommandLookup;
import edu.kit.iti.formal.psdbg.parser.ast.IsClosableCase; import edu.kit.iti.formal.psdbg.parser.ast.tryCase;
import edu.kit.iti.formal.psdbg.parser.types.SimpleType; import edu.kit.iti.formal.psdbg.parser.types.SimpleType;
import lombok.Getter; import lombok.Getter;
import org.key_project.util.collection.ImmutableList; import org.key_project.util.collection.ImmutableList;
...@@ -43,14 +43,14 @@ public class KeyInterpreter extends Interpreter<KeyData> { ...@@ -43,14 +43,14 @@ public class KeyInterpreter extends Interpreter<KeyData> {
@Override @Override
public Object visit(IsClosableCase isClosableCase) { public Object visit(tryCase tryCase) {
State<KeyData> currentStateToMatch = peekState(); State<KeyData> currentStateToMatch = peekState();
State<KeyData> currentStateToMatchCopy = peekState().copy(); //deepcopy State<KeyData> currentStateToMatchCopy = peekState().copy(); //deepcopy
GoalNode<KeyData> selectedGoalNode = currentStateToMatch.getSelectedGoalNode(); GoalNode<KeyData> selectedGoalNode = currentStateToMatch.getSelectedGoalNode();
GoalNode<KeyData> selectedGoalCopy = currentStateToMatch.getSelectedGoalNode().deepCopy(); //deepcopy GoalNode<KeyData> selectedGoalCopy = currentStateToMatch.getSelectedGoalNode().deepCopy(); //deepcopy
enterScope(isClosableCase); enterScope(tryCase);
executeBody(isClosableCase.getBody(), selectedGoalNode, new VariableAssignment(selectedGoalNode.getAssignments())); executeBody(tryCase.getBody(), selectedGoalNode, new VariableAssignment(selectedGoalNode.getAssignments()));
State<KeyData> stateafterIsClosable = peekState(); State<KeyData> stateafterIsClosable = peekState();
List<GoalNode<KeyData>> goals = stateafterIsClosable.getGoals(); List<GoalNode<KeyData>> goals = stateafterIsClosable.getGoals();
boolean allClosed = true; boolean allClosed = true;
...@@ -70,7 +70,7 @@ public class KeyInterpreter extends Interpreter<KeyData> { ...@@ -70,7 +70,7 @@ public class KeyInterpreter extends Interpreter<KeyData> {
pushState(currentStateToMatchCopy); pushState(currentStateToMatchCopy);
} }
//check if state is closed //check if state is closed
exitScope(isClosableCase); exitScope(tryCase);
return false; return false;
} }
} }
...@@ -165,10 +165,10 @@ public class Interpreter<T> extends DefaultASTVisitor<Object> ...@@ -165,10 +165,10 @@ public class Interpreter<T> extends DefaultASTVisitor<Object>
} }
@Override @Override
public Object visit(IsClosableCase isClosableCase) { public Object visit(tryCase tryCase) {
enterScope(isClosableCase); enterScope(tryCase);
exitScope(isClosableCase); exitScope(tryCase);
return false; return false;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment