@@ -177,12 +177,21 @@ package object fastparse {
177177 (implicit ctx : P [Any ]): P [T ] = macro MacroImpls .filterMacro[T ]
178178 /**
179179 * Transforms the result of this parser using the given function into a
180- * new parser which is applied. Useful for doing dependent parsing, e.g.
181- * when parsing JSON you may first parse a character to see if it's a `[`,
182- * ` {`, or `"`, and then deciding whether you next want to parse an array,
183- * dictionary or string.
180+ * new parser which is applied (after whitespace) . Useful for doing
181+ * dependent parsing, e.g. when parsing JSON you may first parse a
182+ * character to see if it's a `[`, ` {`, or `"`, and then deciding whether
183+ * you next want to parse an array, dictionary or string.
184184 */
185- def flatMap [V ](f : T => P [V ]): P [V ] = macro MacroImpls .flatMapMacro[T , V ]
185+ def flatMap [V ](f : T => P [V ])
186+ (implicit whitespace : P [Any ] => P [Unit ]): P [V ] = macro MacroImpls .flatMapMacro[T , V ]
187+ /**
188+ * Transforms the result of this parser using the given function into a
189+ * new parser which is applied (without consuming whitespace). Useful for
190+ * doing dependent parsing, e.g. when parsing JSON you may first parse a
191+ * character to see if it's a `[`, `{`, or `"`, and then deciding whether
192+ * you next want to parse an array, dictionary or string.
193+ */
194+ def flatMapX [V ](f : T => P [V ]): P [V ] = macro MacroImpls .flatMapXMacro[T , V ]
186195
187196 /**
188197 * Either-or operator: tries to parse the left-hand-side, and if that
@@ -195,7 +204,7 @@ package object fastparse {
195204 /**
196205 * Capture operator; makes the parser return the span of input it parsed
197206 * as a [[String ]], which can then be processed further using [[~ ]],
198- * [[map ]] or [[flatMap ]]
207+ * [[map ]] or [[flatMapX ]]
199208 */
200209 def ! (implicit ctx : P [Any ]): P [String ] = macro MacroImpls .captureMacro
201210
@@ -590,9 +599,9 @@ package object fastparse {
590599
591600 /**
592601 * Like [[AnyChar ]], but returns the single character it parses. Useful
593- * together with [[EagerOps.flatMap ]] to provide one-character-lookahead
602+ * together with [[EagerOps.flatMapX ]] to provide one-character-lookahead
594603 * style parsing: [[SingleChar ]] consumes the single character, and then
595- * [[EagerOps.flatMap ]] can `match` on that single character and decide
604+ * [[EagerOps.flatMapX ]] can `match` on that single character and decide
596605 * which downstream parser you wish to invoke
597606 */
598607 def SingleChar (implicit ctx : P [_]): P [Char ] = {
0 commit comments