@@ -90,11 +90,12 @@ object Parser {
90
90
/**
91
91
* Character range like `a-z`.
92
92
*/
93
- def matchCharRange [_ : P ]: P [Range [Char ]] = P (
94
- (singleLitCharClassChar ~ " -" ~ singleLitCharClassChar).map {
95
- case (l, h) => Range (l, h)
96
- }
97
- )
93
+ def matchCharRange [_ : P ]: P [Range [Char ]] =
94
+ P (
95
+ (singleLitCharClassChar ~ " -" ~ singleLitCharClassChar).map {
96
+ case (l, h) => Range (l, h)
97
+ }
98
+ )
98
99
99
100
/**
100
101
* Matches repeat counts like `{3}` or `{1,4}`.
@@ -103,7 +104,9 @@ object Parser {
103
104
P (
104
105
" {" ~/ (
105
106
(posInt ~ " ," ~/ posInt.? ~/ " }" ~/ (P (" ?" ).map(_ => Greediness .NonGreedy ) | Pass (
106
- Greediness .Greedy ))).map { case (l, h, g) => Quantifier .Range (l, h, g) } |
107
+ Greediness .Greedy ))).map {
108
+ case (l, h, g) => Quantifier .Range (l, h, g)
109
+ } |
107
110
(posInt.map(Quantifier .Exact (_)) ~ " }" )
108
111
)
109
112
).opaque(" repeat count such as '{3}', '{1,4}', `{1, 4}?`, '{3,}', or `{3,}?" )
@@ -163,28 +166,30 @@ object Parser {
163
166
(" [" ~ charClassTerm ~ " ]" )
164
167
)
165
168
166
- def base [_ : P ]: P [RegexC [Unit ]] = P (
167
- standardMatchChar.map(lit(_).void) |
168
- (" \\ " ~/ ((" u" ~ unicodeCodePoint | specialChar).map(lit(_).void) | shorthandClass.map(
169
- matching(_).void))) |
170
- wildcard.map(_.void) |
171
- charClass.map(matching(_).void) |
172
- // TODO distinguish between capturing and not?
173
- (" (?:" ~ regex ~ " )" ) |
174
- (" (" ~ regex ~ " )" )
175
- )
176
-
177
- def factor [_ : P ]: P [RegexC [Unit ]] = P {
178
- base.flatMap { r =>
179
- P (" *?" ).map(_ => r.star(Greediness .NonGreedy ).void) |
180
- P (" *" ).map(_ => r.star(Greediness .Greedy ).void) |
181
- P (" +" ).map(_ => r.oneOrMore(Greediness .Greedy ).void) |
182
- P (" ??" ).map(_ => r.optional(Greediness .NonGreedy ).void) |
183
- P (" ?" ).map(_ => r.optional(Greediness .Greedy ).void) |
184
- quantifier.map(q => r.quantifyFold(q, ())((_, _) => ())) |
185
- Pass (r)
169
+ def base [_ : P ]: P [RegexC [Unit ]] =
170
+ P (
171
+ standardMatchChar.map(lit(_).void) |
172
+ (" \\ " ~/ ((" u" ~ unicodeCodePoint | specialChar).map(lit(_).void) | shorthandClass.map(
173
+ matching(_).void))) |
174
+ wildcard.map(_.void) |
175
+ charClass.map(matching(_).void) |
176
+ // TODO distinguish between capturing and not?
177
+ (" (?:" ~ regex ~ " )" ) |
178
+ (" (" ~ regex ~ " )" )
179
+ )
180
+
181
+ def factor [_ : P ]: P [RegexC [Unit ]] =
182
+ P {
183
+ base.flatMap { r =>
184
+ P (" *?" ).map(_ => r.star(Greediness .NonGreedy ).void) |
185
+ P (" *" ).map(_ => r.star(Greediness .Greedy ).void) |
186
+ P (" +" ).map(_ => r.oneOrMore(Greediness .Greedy ).void) |
187
+ P (" ??" ).map(_ => r.optional(Greediness .NonGreedy ).void) |
188
+ P (" ?" ).map(_ => r.optional(Greediness .Greedy ).void) |
189
+ quantifier.map(q => r.quantifyFold(q, ())((_, _) => ())) |
190
+ Pass (r)
191
+ }
186
192
}
187
- }
188
193
189
194
// TODO can probably do better than toList call. Do we care?
190
195
def term [_ : P ]: P [RegexC [Unit ]] = P (factor.rep(0 ).map(_.toList.sequence_))
@@ -193,12 +198,13 @@ object Parser {
193
198
* A parser for a regular expression. You probably want to use [[regexExpr ]] instead, as this
194
199
* parser will succeed even if there are trailing characters after a valid regular expression.
195
200
*/
196
- def regex [_ : P ]: P [RegexC [Unit ]] = P (
197
- term.flatMap { r1 =>
198
- (" |" ~/ regex).map(r2 => r1 | r2) |
199
- Pass (r1)
200
- }
201
- )
201
+ def regex [_ : P ]: P [RegexC [Unit ]] =
202
+ P (
203
+ term.flatMap { r1 =>
204
+ (" |" ~/ regex).map(r2 => r1 | r2) |
205
+ Pass (r1)
206
+ }
207
+ )
202
208
203
209
/**
204
210
* A parser for strings that are complete regular expressions, up until the end of the string.
0 commit comments