@@ -795,27 +795,26 @@ trait Parsers {
795795 /** A parser generator for a specified range of repetitions interleaved by a
796796 * separator.
797797 *
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
799799 * 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).
801801 *
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
804804 * @param p a `Parser` that is to be applied successively to the input
805805 * @param sep a `Parser` that interleaves with p
806806 * @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 `
808808 * (and that only succeeds if `p` matches at least `n` times).
809809 */
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 }
813812 val elems = new ListBuffer [T ]
814813
815814 def continue (in : Input ): ParseResult [List [T ]] = {
816815 val p0 = sep ~> p // avoid repeatedly re-evaluating by-name parser
817816 @ 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)
819818 case e @ Error (_, _) => e // still have to propagate error
820819 case _ => Success (elems.toList, in0)
821820 }
@@ -831,17 +830,17 @@ trait Parsers {
831830
832831 /** A parser generator for a specified range of repetitions.
833832 *
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).
836835 *
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
839838 * @param p a `Parser` that is to be applied successively to the input
840839 * @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 `
842841 * (and that only succeeds if `p` matches at least `n` times).
843842 */
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(()))
845844
846845 /** A parser generator for non-empty repetitions.
847846 *
0 commit comments