Select Git revision
ragconnect.mustache
RobotParser.java 11.18 KiB
package de.tudresden.inf.st.mg;
import de.tudresden.inf.st.mg.common.MotionGrammarParser;
import de.tudresden.inf.st.mg.jastadd.model.*;
public final class RobotParser extends MotionGrammarParser<Tidy> {
private static final String WORLD = "World";
public RobotParser(World world) {
contexts_.put(WORLD, world);
}
private World getWorld() {
return (World) contexts_.get(WORLD);
}
private EmptyTable peekedEmptyTable_ = null;
private NotEmptyTable peekedNotEmptyTable_ = null;
private ObjectAtWrongPlace peekedObjectAtWrongPlace_ = null;
private Pick peekedPick_ = null;
private RobotIsReadyToPickToken peekedRobotIsReadyToPickToken_ = null;
private RobotIsNotReadyToPickToken peekedRobotIsNotReadyToPickToken_ = null;
private RobotIsReadyToDropToken peekedRobotIsReadyToDropToken_ = null;
private RobotIsNotReadyToDropToken peekedRobotIsNotReadyToDropToken_ = null;
private RobotIsIdle peekedRobotIsIdle_ = null;
private RobotIsNotIdle peekedRobotIsNotIdle_ = null;
private RobotHasItemAttached peekedRobotHasItemAttached_ = null;
private RobotHasNoItemAttached peekedRobotHasNoItemAttached_ = null;
private Wait peekedWait_ = null;
private RightPlace peekedRightPlace_ = null;
private Drop peekedDrop_ = null;
@Override
protected void parse(ASTNode<?> parent, int index) throws ParseException {
Tidy result = new Tidy();
parent.setChild(result, index);
while (true) {
peekObjectAtWrongPlace(result);
if (peekedObjectAtWrongPlace_ != null) {
int i = result.getNumMoveObjectToCorrectPlace();
result.addMoveObjectToCorrectPlace(null);
parseMoveObjectToCorrectPlace(result.getMoveObjectToCorrectPlaceList(), i);
} else {
break;
}
}
while (true) {
peekNotEmptyTable();
if (peekedNotEmptyTable_ != null) {
int i = result.getNumWaitForEmptyTable();
result.addWaitForEmptyTable(null);
parseWaitForEmptyTable(result.getWaitForEmptyTableList(), i);
} else {
break;
}
}
parseEmptyTable(result, 2);
// semantic action for T
result.action(getWorld());
printAST("parseTidy", result);
}
private void parseMoveObjectToCorrectPlace(ASTNode<?> parent, int index) throws ParseException {
MoveObjectToCorrectPlace result = new MoveObjectToCorrectPlace();
parent.setChild(result, index);
parseObjectAtWrongPlace(result, 0, parent.containingTidy());
parsePickUpObject(result, 1);
parseDropObjectAtRightPlace(result, 2);
// semantic action for MoveObjectToCorrectPlace
result.action(getWorld());
printAST("parseMoveObjectToCorrectPlace", result);
}
private void parseWaitForEmptyTable(ASTNode<?> parent, int index) throws ParseException {
WaitForEmptyTable result = new WaitForEmptyTable();
parent.setChild(result, index);
parseNotEmptyTable(result, 0);
parseWait(result, 1);
// semantic action for WaitForEmptyTable
result.action(getWorld());
printAST("parseWaitForEmptyTable", result);
}
private void parseDropObjectAtRightPlace(ASTNode<?> parent, int index) throws ParseException {
DropObjectAtRightPlace result = new DropObjectAtRightPlace();
parent.setChild(result, index);
parseRightPlace(result, 0);
parseDrop(result, 1);
// semantic action for DropObjectAtRightPlace
result.action(getWorld());
printAST("parseDropObjectAtRightPlace", result);
}
private void parseDrop(ASTNode<?> parent, int index) throws ParseException {
Drop result;
if (peekedDrop_ != null) {
result = peekedDrop_;
peekedDrop_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseDrop(parent.object(), parent.place());
if (result == null) {
throw new ParseException(Drop.type());
}
}
parent.setChild(result, index);
// semantic action for Drop
result.action(getWorld());
printAST("parseDrop", result);
}
private void parseRightPlace(ASTNode<?> parent, int index) throws ParseException {
RightPlace result;
if (peekedRightPlace_ != null) {
result = peekedRightPlace_;
peekedRightPlace_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseRightPlace(parent.object());
if (result == null) {
throw new ParseException(RightPlace.type());
}
}
parent.setChild(result, index);
// semantic action for RightPlace
result.action(getWorld());
printAST("parseRightPlace", result);
}
private void parsePickUpObject(ASTNode<?> parent, int index) throws ParseException {
PickUpObject result = new PickUpObject();
parent.setChild(result, index);
parseRobotIsReadyToPick(result, 0);
parsePick(result, 1);
// semantic action for T1
result.action(getWorld());
printAST("parsePickUpObject", result);
}
private void parsePick(ASTNode<?> parent, int index) throws ParseException {
Pick result;
if (peekedPick_ != null) {
result = peekedPick_;
peekedPick_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parsePick(parent.object());
if (result == null) {
throw new ParseException(Pick.type());
}
}
parent.setChild(result, index);
// semantic action for Pick
result.action(getWorld());
printAST("parsePick", result);
}
private void parseRobotIsReadyToPick(ASTNode<?> parent, int index) throws ParseException {
RobotIsReadyToPick result;
// try to parse a RobotIsReadyToPickToken
if (peekRobotIsReadyToPickToken()) {
result = new RobotIsReallyReadyToPick();
parent.setChild(result, index);
parseRobotIsReallyReadyToPick(parent, index);
} else if (peekRobotIsNotReadyToPickToken()) {
result = new RobotIsNotReadyToPick();
parent.setChild(result, index);
parseRobotIsNotReadyToPick(parent, index);
} else {
throw new ParseException("RobotIsReadyToPick", RobotIsReadyToPickToken.type(), RobotIsNotIdle.type());
}
// semantic action for T1
result.action(getWorld());
printAST("parseRobotIsReadyToPick", result);
}
private void parseRobotIsReallyReadyToPick(ASTNode<?> parent, int index) throws ParseException {
RobotIsReallyReadyToPick result = (RobotIsReallyReadyToPick) parent.getChild(index);
parseRobotIsReadyToPickToken(result, 0);
// semantic action for T1
result.action(getWorld());
printAST("parseRobotIsReallyReadyToPick", result);
}
private boolean peekRobotIsReadyToPickToken() {
peekedRobotIsReadyToPickToken_ = getWorld().parseRobotIsReadyToPickToken();
return peekedRobotIsReadyToPickToken_ != null;
}
private void parseRobotIsReadyToPickToken(ASTNode<?> parent, int index) throws ParseException {
RobotIsReadyToPickToken result;
if (peekedRobotIsReadyToPickToken_ != null) {
result = peekedRobotIsReadyToPickToken_;
peekedRobotIsReadyToPickToken_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseRobotIsReadyToPickToken();
if (result == null) {
throw new ParseException(RobotIsReadyToPickToken.type());
}
}
parent.setChild(result, index);
// semantic action for RobotIsReadyToPickToken
result.action(getWorld());
printAST("parseRobotIsReadyToPickToken", result);
}
private void parseRobotIsNotReadyToPick(ASTNode<?> parent, int index) throws ParseException {
RobotIsNotReadyToPick result = (RobotIsNotReadyToPick) parent.getChild(index);
parseRobotIsNotIdle(result, 0);
parseWait(result, 1);
parseRobotIsReadyToPick(result, 2);
// semantic action for T1
result.action(getWorld());
printAST("parseRobotIsNotReadyToPick", result);
}
private boolean peekRobotIsNotIdle() {
peekedRobotIsNotIdle_ = getWorld().parseRobotIsNotIdle();
return peekedRobotIsNotIdle_ != null;
}
private void parseRobotIsNotIdle(ASTNode<?> parent, int index) throws ParseException {
RobotIsNotIdle result;
if (peekedRobotIsNotIdle_ != null) {
result = peekedRobotIsNotIdle_;
peekedRobotIsNotIdle_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseRobotIsNotIdle();
if (result == null) {
throw new ParseException(RobotIsNotIdle.type());
}
}
parent.setChild(result, index);
// semantic action for RobotIsNotIdle
result.action(getWorld());
printAST("parseRobotIsNotIdle", result);
}
private void parseWait(ASTNode<?> parent, int index) throws ParseException {
Wait result;
if (peekedWait_ != null) {
result = peekedWait_;
peekedWait_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseWait(parent.time());
if (result == null) {
throw new ParseException(Wait.type());
}
}
parent.setChild(result, index);
// semantic action for Wait
result.action(getWorld());
printAST("parseWait", result);
}
private boolean peekObjectAtWrongPlace(Tidy context) {
peekedObjectAtWrongPlace_ = getWorld().parseObjectAtWrongPlace(context);
return peekedObjectAtWrongPlace_ != null;
}
private void parseObjectAtWrongPlace(ASTNode<?> parent, int index, Tidy context) throws ParseException {
ObjectAtWrongPlace result;
if (peekedObjectAtWrongPlace_ != null) {
result = peekedObjectAtWrongPlace_;
peekedObjectAtWrongPlace_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseObjectAtWrongPlace(context);
if (result == null) {
throw new ParseException(ObjectAtWrongPlace.type());
}
}
parent.setChild(result, index);
// semantic action for ObjectAtWrongPlace
result.action(getWorld());
printAST("parseObjectAtWrongPlace", result);
}
private void parseEmptyTable(ASTNode<?> parent, int index) throws ParseException {
EmptyTable result;
if (peekedEmptyTable_ != null) {
result = peekedEmptyTable_;
peekedEmptyTable_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseEmptyTable();
if (result == null) {
throw new ParseException(EmptyTable.type());
}
}
parent.setChild(result, index);
// semantic action for EmptyTable
result.action(getWorld());
printAST("parseEmptyTable", result);
}
private boolean peekNotEmptyTable() {
peekedNotEmptyTable_ = getWorld().parseNotEmptyTable();
return peekedNotEmptyTable_ != null;
}
private void parseNotEmptyTable(ASTNode<?> parent, int index) throws ParseException {
NotEmptyTable result;
if (peekedNotEmptyTable_ != null) {
result = peekedNotEmptyTable_;
peekedNotEmptyTable_ = null; // TODO check if all peeked values are actually parsed afterwards
} else {
result = getWorld().parseNotEmptyTable();
if (result == null) {
throw new ParseException(NotEmptyTable.type());
}
}
parent.setChild(result, index);
// semantic action for NotEmptyTable
result.action(getWorld());
printAST("parseNotEmptyTable", result);
}
}