Skip to content
Snippets Groups Projects
Commit ae2df97e authored by Johannes Mey's avatar Johannes Mey
Browse files

fix world problem

parent 6f9b6e24
No related branches found
No related tags found
No related merge requests found
Pipeline #13386 failed
......@@ -14,11 +14,9 @@ aspect World {
return print();
}
public enum TokenType {UNDEFINED,FULL,LOAD,UNLOAD; }
public static TokenType Token.type() {return TokenType.UNDEFINED; }
public static TokenType Full.type() {return TokenType.FULL; }
public static TokenType Load.type() {return TokenType.LOAD; }
public static TokenType Unload.type() {return TokenType.UNLOAD; }
public static TokenType Full.type() {return TokenType.of("FULL"); }
public static TokenType Load.type() {return TokenType.of("LOAD"); }
public static TokenType Unload.type() {return TokenType.of("UNLOAD"); }
public Full World.parseFull() {
return null;
......
aspect LoadWorld {
syn String Container.print() = "[Container " + getElementCount() + "/" + getCapacity() + "]";
syn Container World.asContainer() = null;
eq Container.asContainer() = this;
}
\ No newline at end of file
......@@ -12,6 +12,17 @@ aspect RobotWorld {
return new RobotScene(t, b);
}
public static TokenType EmptyTable.type() { return TokenType.of("EMPTY_TABLE"); }
public static TokenType ObjectAtWrongPlace.type() { return TokenType.of("OBJECT_AT_WRONG_PLACE"); }
public static TokenType Pick.type() { return TokenType.of("PICK"); }
public static TokenType RobotIsFree.type() { return TokenType.of("ROBOT_IS_FREE"); }
public static TokenType RobotIsBusy.type() { return TokenType.of("ROBOT_IS_BUSY"); }
public static TokenType RobotIsIdle.type() { return TokenType.of("ROBOT_IS_IDLE"); }
public static TokenType RobotHasNoItemAttached.type() { return TokenType.of("ROBOT_HAS_NO_ITEM_ATTACHED"); }
public static TokenType Wait.type() { return TokenType.of("WAIT"); }
public static TokenType RightPlace.type() { return TokenType.of("RIGHT_PLACE"); }
public static TokenType Drop.type() { return TokenType.of("DROP"); }
public static Pose Pose.of(double x, double y, double z) {
return new Pose(x, y, z, 0, 0, 0, 1);
}
......
......@@ -7,6 +7,9 @@ aspect RobotWorld {
return result + "\n]\n";
}
syn RobotScene World.asRobotScene() = null;
eq RobotScene.asRobotScene() = this;
syn boolean PhysicalObject.isBin() = false;
eq Bin.isBin() = true;
......
aspect SemanticActions {
@Override
public void Load.action(World world) {
Container container = world.asContainer();
System.out.println("performing semantic action for element Load");
System.out.print(" " + world);
world.setElementCount(world.getElementCount() + 1);
container.setElementCount(world.asContainer().getElementCount() + 1);
System.out.println(" -> " + world);
}
@Override
public void Unload.action(World world) {
Container container = world.asContainer();
System.out.println("performing semantic action for element Unload");
System.out.print(" " + world);
world.setElementCount(world.getElementCount() - 1);
container.setElementCount(container.getElementCount() - 1);
System.out.println(" -> " + world);
}
}
\ No newline at end of file
aspect SemanticActions {
public void MotionGrammarElement.action(World world) {
System.out.println("performing semantic action for element " + getClass().getSimpleName());
System.out.println("NOT performing any semantic action for element " + getClass().getSimpleName());
}
}
\ No newline at end of file
aspect Tokens {
public class TokenType {
private String name_;
private TokenType(String name) {
name_ = name;
}
public String name() {
return name_;
}
public static TokenType of(String name) {
return new TokenType(name);
}
}
public static TokenType Token.type() {return TokenType.of("UNDEFINED"); }
}
\ No newline at end of file
......@@ -5,7 +5,7 @@ import de.tudresden.inf.st.mg.jastadd.model.*;
public final class WorldParser extends MotionGrammarParser<T> {
public final class LoadWorldParser extends MotionGrammarParser<T> {
private static final String WORLD = "World";
......@@ -13,12 +13,12 @@ public final class WorldParser extends MotionGrammarParser<T> {
private Unload peekedUnload_ = null;
private Full peekedFull_ = null;
public WorldParser(World world) {
context_.put(WORLD, world);
public LoadWorldParser(World world) {
contexts_.put(WORLD, world);
}
private World getWorld() {
return (World) context_.get(WORLD);
return (World) contexts_.get(WORLD);
}
@Override
......
......@@ -11,11 +11,11 @@ public final class RobotParser extends MotionGrammarParser<Tidy> {
private ObjectAtWrongPlace peekedObjectAtWrongPlace_ = null;
public RobotParser(World world) {
context_.put(WORLD, world);
contexts_.put(WORLD, world);
}
private World getWorld() {
return (World) context_.get(WORLD);
return (World) contexts_.get(WORLD);
}
......
......@@ -2,7 +2,10 @@ package de.tudresden.inf.st.mg.common;
import de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper;
import de.tudresden.inf.st.jastadd.dumpAst.ast.SkinParamBooleanSetting;
import de.tudresden.inf.st.mg.jastadd.model.*;
import de.tudresden.inf.st.mg.jastadd.model.ASTNode;
import de.tudresden.inf.st.mg.jastadd.model.MotionGrammarElement;
import de.tudresden.inf.st.mg.jastadd.model.Token;
import de.tudresden.inf.st.mg.jastadd.model.TokenType;
import java.io.IOException;
import java.nio.file.Path;
......@@ -13,7 +16,7 @@ import java.util.stream.Collectors;
public abstract class MotionGrammarParser<T extends MotionGrammarElement> {
protected final Map<String, ASTNode<?>> context_ = new HashMap<>();
protected final Map<String, ASTNode<?>> contexts_ = new HashMap<>();
protected ASTNode<T> rootContainer_;
private int timeStep_;
protected Path astDiagramDir_;
......@@ -41,7 +44,7 @@ public abstract class MotionGrammarParser<T extends MotionGrammarElement> {
try {
for (var contextEntry : context_.entrySet()) {
for (var contextEntry : contexts_.entrySet()) {
Dumper.read(contextEntry.getValue())
.setNameMethod(o -> o == null ? "null" : o.getClass().getSimpleName())
.dumpAsPNG(astDiagramDir_.resolve("Context-" + contextEntry.getKey() + "-" + String.format("%03d", timeStep_) + "-" + step + ".png"));
......@@ -63,7 +66,7 @@ public abstract class MotionGrammarParser<T extends MotionGrammarElement> {
public static class ParseException extends Exception {
public ParseException(String ruleName, TokenType... expectedTokens) {
super("Unable to parse nonterminal " + ruleName + ". Expected tokens " + Arrays.stream(expectedTokens).map(Enum::toString).collect(Collectors.joining(", ")) + ".");
super("Unable to parse nonterminal " + ruleName + ". Expected tokens " + Arrays.stream(expectedTokens).map(Object::toString).collect(Collectors.joining(", ")) + ".");
}
public ParseException(TokenType expectedToken) {
......
......@@ -44,7 +44,7 @@ public class ParserTest {
// for some reason, the best random seed value here is 1 and not 0???
Container containerWorld = Container.initialWorld(new Random(1));
WorldParser parser = new WorldParser(containerWorld);
LoadWorldParser parser = new LoadWorldParser(containerWorld);
parser.setDebugDiagramDir(LOAD_AST_DIAGRAM_DIR);
var result = parser.parse();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment