package foam.lib.parse;

import java.util.ArrayList;

public class Repeat0 implements Parser {
  private Parser p;
  private Parser delim;
  private int min;
  private int max;

  public Repeat0(Parser parser) {
    this(parser, null);
  }

  public Repeat0(Parser parser, Parser delimiter) {
    this(parser, delimiter, -1, -1);
  }

  public Repeat0(Parser parser, Parser delimiter, int minimum) {
    this(parser, delimiter, minimum, -1);
  }

  public Repeat0(Parser parser, Parser delimiter, int minimum, int maximum) {
    p = parser;
    delim = delimiter;
    min = minimum;
    max = maximum;
  }

  public PStream parse(PStream ps, ParserContext x) {
    ArrayList values = new ArrayList();
    PStream result;
    int i;

    for ( i = 0 ; max == -1 || i < max ; i++ ) {
      if ( delim != null && values.size() != 0 ) {
        result = delim.parse(ps, x);
        if ( result == null ) break;
        ps = result;
      }

      result = p.parse(ps, x);
      if ( result == null ) break;
      ps = result;
    }

    if ( min != -1 && i < min ) return null;

    return ps;
  }
}

@@ -662,42 +662,28 @@
     
-ArrayList values = new ArrayList()
+boolean first = true
 ;%0A  
@@ -793,26 +793,15 @@
  && 
-values.size() != 0
+! first
  ) %7B
@@ -986,24 +986,45 @@
 s = result;%0A
+      first = false;%0A
     %7D%0A%0A    i

Fix Repeat0 parser.