/**
 * @license
 * Copyright 2016 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package foam.lib.parse;

public class Seq
  implements Parser
{
  protected Parser[] parsers;

  public Seq(Parser... args) {
    parsers = args;
  }

  public PStream parse(PStream ps, ParserContext x) {
    Object[] values = new Object[parsers.length];

    for ( int i = 0 ; i < parsers.length ; i++ ) {
      ps = ps.apply(parsers[i], x);
      if ( ps == null ) return null;
      values[i] = ps.value();
    }

    return ps.setValue(values);
  }
}

@@ -648,16 +648,40 @@
 parse;%0A%0A
+import java.util.List;%0A%0A
 public c
@@ -739,17 +739,134 @@
  parsers
-;
+_;%0A%0A  public Seq(List%3CParser%3E parsers) %7B%0A    parsers_ = new Parser%5Bparsers.size()%5D;%0A    parsers.toArray(parsers_);%0A  %7D
 %0A%0A  publ
@@ -901,16 +901,17 @@
  parsers
+_
  = args;
@@ -1006,24 +1006,25 @@
 ject%5Bparsers
+_
 .length%5D;%0A%0A 
@@ -1055,16 +1055,17 @@
  parsers
+_
 .length 
@@ -1101,16 +1101,17 @@
 (parsers
+_
 %5Bi%5D, x);

Add convenience constructor to Seq parser.