Skip to content
Snippets Groups Projects
Select Git revision
  • e7fd4453e28f8de9fe7bca57d92057262159c75b
  • main default protected
  • feature/waiting
  • feature/control
  • feature/tracing
  • feature/demo
  • wip
7 results

RobotParser.java

Blame
  • Johannes Mey's avatar
    Johannes Mey authored
    e7fd4453
    History
    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);
      }
    }