Select Git revision
RobotParser.java

Johannes Mey authored
RobotParser.java 1.81 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";
private ObjectAtWrongPlace peekedObjectAtWrongPlace_ = null;
public RobotParser(World world) {
context_.put(WORLD, world);
}
private World getWorld() {
return (World) context_.get(WORLD);
}
@Override
protected void parse(ASTNode<?> parent, int index) throws ParseException {
Tidy result = new Tidy();
parent.setChild(result, index);
while (true) {
peekObjectAtWrongPlace();
if (peekedObjectAtWrongPlace_ != null) {
parseObjectAtWrongPlace(result.getMoveObjectToCorrectPlaceList(), result.getNumMoveObjectToCorrectPlace());
} else {
break;
}
}
// TODO implement
// parseEmptyTable(result, 1);
// semantic action for T
result.action(getWorld());
printAST("parseTidy", result);
}
private boolean peekObjectAtWrongPlace() {
peekedObjectAtWrongPlace_ = getWorld().parseObjectAtWrongPlace();
return peekedObjectAtWrongPlace_ != null;
}
private void parseObjectAtWrongPlace(ASTNode<?> parent, int index) 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();
if (result == null) {
throw new ParseException(ObjectAtWrongPlace.type());
}
}
parent.setChild(result, index);
// semantic action for Unload
result.action(getWorld());
printAST("parseObjectAtWrongPlace", result);
}
}