@@ -127,7 +127,17 @@ abstract class RegexString extends Expr {
127
127
result = this .( Unicode ) .getText ( )
128
128
}
129
129
130
- /** result is true for those start chars that actually mark a start of a char set. */
130
+ /**
131
+ * Helper predicate for `char_set_start(int start, int end)`.
132
+ *
133
+ * In order to identify left brackets ('[') which actually start a character class,
134
+ * we perform a left to right scan of the string.
135
+ *
136
+ * To avoid negative recursion we return a boolean. See `escaping`,
137
+ * the helper for `escapingChar`, for a clean use of this pattern.
138
+ *
139
+ * result is true for those start chars that actually mark a start of a char set.
140
+ */
131
141
boolean char_set_start ( int pos ) {
132
142
exists ( int index |
133
143
// is opening bracket
@@ -176,9 +186,9 @@ abstract class RegexString extends Expr {
176
186
)
177
187
}
178
188
179
- /**
180
- * Helper predicate for chars that could be character-set delimiters.
181
- * Holds if the (non-escaped) char at `pos` in the string, is the (one-based) `index` occurrence of a bracket (`[` or `]`) in the string.
189
+ /**
190
+ * Helper predicate for chars that could be character-set delimiters.
191
+ * Holds if the (non-escaped) char at `pos` in the string, is the (one-based) `index` occurrence of a bracket (`[` or `]`) in the string.
182
192
* Result if `true` is the char is `[`, and `false` if the char is `]`.
183
193
*/
184
194
boolean char_set_delimiter ( int index , int pos ) {
@@ -267,6 +277,13 @@ abstract class RegexString extends Expr {
267
277
)
268
278
}
269
279
280
+ /**
281
+ * Helper predicate for `charRange`.
282
+ * We can determine where character ranges end by a left to right sweep.
283
+ *
284
+ * To avoid negative recursion we return a boolean. See `escaping`,
285
+ * the helper for `escapingChar`, for a clean use of this pattern.
286
+ */
270
287
private boolean charRangeEnd ( int charset_start , int index ) {
271
288
this .char_set_token ( charset_start , index , _, _) and
272
289
(
@@ -290,8 +307,15 @@ abstract class RegexString extends Expr {
290
307
)
291
308
}
292
309
310
+ /** Holds if the character at `pos` is a "\" that is actually escaping what comes after. */
293
311
predicate escapingChar ( int pos ) { this .escaping ( pos ) = true }
294
312
313
+ /**
314
+ * Helper predicate for `escapingChar`.
315
+ * In order to avoid negative recusrion, we return a boolean.
316
+ * This way, we can refer to `escaping(pos - 1).booleanNot()`
317
+ * rather than to a negated version of `escaping(pos)`.
318
+ */
295
319
private boolean escaping ( int pos ) {
296
320
pos = - 1 and result = false
297
321
or
0 commit comments