@@ -177,12 +177,21 @@ package object fastparse {
177
177
(implicit ctx : P [Any ]): P [T ] = macro MacroImpls .filterMacro[T ]
178
178
/**
179
179
* 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.
184
184
*/
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 ]
186
195
187
196
/**
188
197
* Either-or operator: tries to parse the left-hand-side, and if that
@@ -195,7 +204,7 @@ package object fastparse {
195
204
/**
196
205
* Capture operator; makes the parser return the span of input it parsed
197
206
* as a [[String ]], which can then be processed further using [[~ ]],
198
- * [[map ]] or [[flatMap ]]
207
+ * [[map ]] or [[flatMapX ]]
199
208
*/
200
209
def ! (implicit ctx : P [Any ]): P [String ] = macro MacroImpls .captureMacro
201
210
@@ -590,9 +599,9 @@ package object fastparse {
590
599
591
600
/**
592
601
* 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
594
603
* 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
596
605
* which downstream parser you wish to invoke
597
606
*/
598
607
def SingleChar (implicit ctx : P [_]): P [Char ] = {
0 commit comments