Skip to content

Commit da931e4

Browse files
Copilotjketema
authored andcommitted
C++: Remove lookbehind assertions
1 parent bb96e90 commit da931e4

2 files changed

Lines changed: 3 additions & 87 deletions

File tree

‎cpp/ql/lib/semmle/code/cpp/regex/RegexTreeView.qll‎

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -993,15 +993,13 @@ private module Impl implements RegexTreeViewSig {
993993
}
994994

995995
/**
996-
* A zero-width lookahead or lookbehind assertion.
996+
* A zero-width lookahead assertion.
997997
*
998998
* Examples:
999999
*
10001000
* ```
10011001
* (?=\w)
10021002
* (?!\n)
1003-
* (?<=\.)
1004-
* (?<!\\)
10051003
* ```
10061004
*/
10071005
class RegExpSubPattern extends RegExpZeroWidthMatch {
@@ -1063,47 +1061,9 @@ private module Impl implements RegexTreeViewSig {
10631061
override string getAPrimaryQlClass() { result = "RegExpNegativeLookahead" }
10641062
}
10651063

1066-
/**
1067-
* A zero-width lookbehind assertion.
1068-
*
1069-
* Examples:
1070-
*
1071-
* ```
1072-
* (?<=\.)
1073-
* (?<!\\)
1074-
* ```
1075-
*/
10761064
abstract class RegExpLookbehind extends RegExpSubPattern { }
10771065

1078-
/**
1079-
* A positive-lookbehind assertion.
1080-
*
1081-
* Examples:
1082-
*
1083-
* ```
1084-
* (?<=\.)
1085-
* ```
1086-
*/
1087-
class RegExpPositiveLookbehind extends RegExpLookbehind {
1088-
RegExpPositiveLookbehind() { re.positiveLookbehindAssertionGroup(start, end) }
1089-
1090-
override string getAPrimaryQlClass() { result = "RegExpPositiveLookbehind" }
1091-
}
1092-
1093-
/**
1094-
* A negative-lookbehind assertion.
1095-
*
1096-
* Examples:
1097-
*
1098-
* ```
1099-
* (?<!\\)
1100-
* ```
1101-
*/
1102-
additional class RegExpNegativeLookbehind extends RegExpLookbehind {
1103-
RegExpNegativeLookbehind() { re.negativeLookbehindAssertionGroup(start, end) }
1104-
1105-
override string getAPrimaryQlClass() { result = "RegExpNegativeLookbehind" }
1106-
}
1066+
abstract class RegExpPositiveLookbehind extends RegExpLookbehind { }
11071067

11081068
/**
11091069
* A back reference, that is, a term of the form `\i` in a regular

‎cpp/ql/lib/semmle/code/cpp/regex/internal/ParseRegExp.qll‎

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -501,8 +501,6 @@ abstract class RegExp extends StringLiteral {
501501
this.negativeAssertionGroup(start, end)
502502
or
503503
this.positiveLookaheadAssertionGroup(start, end)
504-
or
505-
this.positiveLookbehindAssertionGroup(start, end)
506504
}
507505

508506
/** Holds if an empty group is found between `start` and `end`. */
@@ -525,16 +523,10 @@ abstract class RegExp extends StringLiteral {
525523
this.emptyGroup(start, end)
526524
or
527525
this.negativeAssertionGroup(start, end)
528-
or
529-
this.positiveLookbehindAssertionGroup(start, end)
530526
}
531527

532528
private predicate negativeAssertionGroup(int start, int end) {
533-
exists(int inStart |
534-
this.negativeLookaheadAssertionStart(start, inStart)
535-
or
536-
this.negativeLookbehindAssertionStart(start, inStart)
537-
|
529+
exists(int inStart | this.negativeLookaheadAssertionStart(start, inStart) |
538530
this.groupContents(start, end, inStart, _)
539531
)
540532
}
@@ -546,38 +538,20 @@ abstract class RegExp extends StringLiteral {
546538
)
547539
}
548540

549-
/** Holds if a negative lookbehind is found between `start` and `end` */
550-
predicate negativeLookbehindAssertionGroup(int start, int end) {
551-
exists(int inStart | this.negativeLookbehindAssertionStart(start, inStart) |
552-
this.groupContents(start, end, inStart, _)
553-
)
554-
}
555-
556541
/** Holds if a positive lookahead is found between `start` and `end` */
557542
predicate positiveLookaheadAssertionGroup(int start, int end) {
558543
exists(int inStart | this.lookaheadAssertionStart(start, inStart) |
559544
this.groupContents(start, end, inStart, _)
560545
)
561546
}
562547

563-
/** Holds if a positive lookbehind is found between `start` and `end` */
564-
predicate positiveLookbehindAssertionGroup(int start, int end) {
565-
exists(int inStart | this.lookbehindAssertionStart(start, inStart) |
566-
this.groupContents(start, end, inStart, _)
567-
)
568-
}
569-
570548
private predicate groupStart(int start, int end) {
571549
this.nonCapturingGroupStart(start, end)
572550
or
573551
this.lookaheadAssertionStart(start, end)
574552
or
575553
this.negativeLookaheadAssertionStart(start, end)
576554
or
577-
this.lookbehindAssertionStart(start, end)
578-
or
579-
this.negativeLookbehindAssertionStart(start, end)
580-
or
581555
this.simpleGroupStart(start, end)
582556
}
583557

@@ -612,24 +586,6 @@ abstract class RegExp extends StringLiteral {
612586
end = start + 3
613587
}
614588

615-
/** Matches the start of a positive lookbehind assertion, i.e. `(?<=`. */
616-
private predicate lookbehindAssertionStart(int start, int end) {
617-
this.isGroupStart(start) and
618-
this.getChar(start + 1) = "?" and
619-
this.getChar(start + 2) = "<" and
620-
this.getChar(start + 3) = "=" and
621-
end = start + 4
622-
}
623-
624-
/** Matches the start of a negative lookbehind assertion, i.e. `(?<!`. */
625-
private predicate negativeLookbehindAssertionStart(int start, int end) {
626-
this.isGroupStart(start) and
627-
this.getChar(start + 1) = "?" and
628-
this.getChar(start + 2) = "<" and
629-
this.getChar(start + 3) = "!" and
630-
end = start + 4
631-
}
632-
633589
/** Matches the contents of a group. */
634590
predicate groupContents(int start, int end, int inStart, int inEnd) {
635591
this.groupStart(start, inStart) and

0 commit comments

Comments
 (0)