Esempio n. 1
0
  @Override
  public String visitLoop(@NotNull DiceGameParser.LoopContext ctx) {

    if (ctx.FORLOOP != null) {
      StringBuilder forLoop = new StringBuilder();
      if (ctx.POs != null) {
        forLoop.append("for self." + ctx.VAR.getText() + " in " + ctx.POs.accept(this) + ":\n");
      }
      if (ctx.DOs != null) {
        forLoop.append("for self." + ctx.VAR.getText() + " in " + ctx.DOs.accept(this) + ":\n");
      }
      forLoop.append(indent(ctx.ACTION.accept(this)));
      return forLoop.toString();
    }
    if (ctx.NLOOP != null) {
      StringBuilder loop = new StringBuilder();
      loop.append("for i in range(" + ctx.VALUE.getText() + "):\n");
      loop.append(indent(ctx.ACTION.accept(this)));
      return loop.toString();
    }
    return "visitLoop";
  }