@@ -795,27 +795,26 @@ trait Parsers {
795
795
/** A parser generator for a specified range of repetitions interleaved by a
796
796
* separator.
797
797
*
798
- * `repN (n, m, p, s)` uses `p` at least `m ` times and up to `n ` times, interleaved
798
+ * `repNM (n, m, p, s)` uses `p` at least `n ` times and up to `m ` times, interleaved
799
799
* with separator `s`, to parse the input
800
- * (the result is a `List` of at least `m ` consecutive results of `p` and up to `n ` results).
800
+ * (the result is a `List` of at least `n ` consecutive results of `p` and up to `m ` results).
801
801
*
802
- * @param m minimum number of repetitions
803
- * @param n maximum number of repetitions
802
+ * @param n minimum number of repetitions
803
+ * @param m maximum number of repetitions
804
804
* @param p a `Parser` that is to be applied successively to the input
805
805
* @param sep a `Parser` that interleaves with p
806
806
* @return A parser that returns a list of results produced by repeatedly applying `p` interleaved
807
- * with `sep` to the input. The list has a size between `m ` and up to `n `
807
+ * with `sep` to the input. The list has a size between `n ` and up to `m `
808
808
* (and that only succeeds if `p` matches at least `n` times).
809
809
*/
810
- def repMN [T ](m : Int , n : Int , p : Parser [T ], sep : Parser [Any ]): Parser [List [T ]] = Parser { in =>
811
- require(0 <= m && m <= n)
812
- val mandatory = if (m == 0 ) success(Nil ) else (p ~ repN(m - 1 , sep ~> p)).map { case head ~ tail => head :: tail }
810
+ def repNM [T ](n : Int , m : Int , p : Parser [T ], sep : Parser [Any ]): Parser [List [T ]] = Parser { in =>
811
+ val mandatory = if (n == 0 ) success(Nil ) else (p ~ repN(n - 1 , sep ~> p)).map { case head ~ tail => head :: tail }
813
812
val elems = new ListBuffer [T ]
814
813
815
814
def continue (in : Input ): ParseResult [List [T ]] = {
816
815
val p0 = sep ~> p // avoid repeatedly re-evaluating by-name parser
817
816
@ tailrec def applyp (in0 : Input ): ParseResult [List [T ]] = p0(in0) match {
818
- case Success (x, rest) => elems += x; if (elems.length == n ) Success (elems.toList, rest) else applyp(rest)
817
+ case Success (x, rest) => elems += x; if (elems.length == m ) Success (elems.toList, rest) else applyp(rest)
819
818
case e @ Error (_, _) => e // still have to propagate error
820
819
case _ => Success (elems.toList, in0)
821
820
}
@@ -831,17 +830,17 @@ trait Parsers {
831
830
832
831
/** A parser generator for a specified range of repetitions.
833
832
*
834
- * `repN (n, m, p)` uses `p` at least `m ` times and up to `n ` times to parse the input
835
- * (the result is a `List` of at least `m ` consecutive results of `p` and up to `n ` results).
833
+ * `repNM (n, m, p)` uses `p` at least `n ` times and up to `m ` times to parse the input
834
+ * (the result is a `List` of at least `n ` consecutive results of `p` and up to `m ` results).
836
835
*
837
- * @param m minimum number of repetitions
838
- * @param n maximum number of repetitions
836
+ * @param n minimum number of repetitions
837
+ * @param m maximum number of repetitions
839
838
* @param p a `Parser` that is to be applied successively to the input
840
839
* @return A parser that returns a list of results produced by repeatedly applying `p` to the input.
841
- * The list has a size between `m ` and up to `n `
840
+ * The list has a size between `n ` and up to `m `
842
841
* (and that only succeeds if `p` matches at least `n` times).
843
842
*/
844
- def repMN [T ](m : Int , n : Int , p : Parser [T ]): Parser [List [T ]] = repMN [T ](m, n , p, success(()))
843
+ def repNM [T ](n : Int , m : Int , p : Parser [T ]): Parser [List [T ]] = repNM [T ](n, m , p, success(()))
845
844
846
845
/** A parser generator for non-empty repetitions.
847
846
*
0 commit comments