@@ -49,6 +49,7 @@ newtype TRegExpParent =
49
49
* or another regular expression term.
50
50
*/
51
51
class RegExpParent extends TRegExpParent {
52
+ /** Gets a textual representation of this element. */
52
53
string toString ( ) { result = "RegExpParent" }
53
54
54
55
/** Gets the `i`th child term. */
@@ -72,14 +73,18 @@ class RegExpLiteral extends TRegExpLiteral, RegExpParent {
72
73
73
74
override RegExpTerm getChild ( int i ) { i = 0 and result .getRegex ( ) = re and result .isRootTerm ( ) }
74
75
76
+ /** Holds if dot, `.`, matches all characters, including newlines. */
75
77
predicate isDotAll ( ) { re .getAMode ( ) = "DOTALL" }
76
78
79
+ /** Holds if this regex matching is case-insensitive for this regex. */
77
80
predicate isIgnoreCase ( ) { re .getAMode ( ) = "IGNORECASE" }
78
81
82
+ /** Get a string representing all modes for this regex. */
79
83
string getFlags ( ) { result = concat ( string mode | mode = re .getAMode ( ) | mode , " | " ) }
80
84
81
85
override Regex getRegex ( ) { result = re }
82
86
87
+ /** Gets the primary QL class for this regex. */
83
88
string getPrimaryQLClass ( ) { result = "RegExpLiteral" }
84
89
}
85
90
@@ -246,8 +251,10 @@ class RegExpQuantifier extends RegExpTerm, TRegExpQuantifier {
246
251
result .getEnd ( ) = part_end
247
252
}
248
253
254
+ /** Hols if this term may match an unlimited number of times. */
249
255
predicate mayRepeatForever ( ) { may_repeat_forever = true }
250
256
257
+ /** Gets the qualifier for this term. That is e.g "?" for "a?". */
251
258
string getQualifier ( ) { result = re .getText ( ) .substring ( part_end , end ) }
252
259
253
260
override string getPrimaryQLClass ( ) { result = "RegExpQuantifier" }
@@ -322,8 +329,10 @@ class RegExpRange extends RegExpQuantifier {
322
329
323
330
RegExpRange ( ) { re .multiples ( part_end , end , lower , upper ) }
324
331
332
+ /** Gets the string defining the upper bound of this range, if any. */
325
333
string getUpper ( ) { result = upper }
326
334
335
+ /** Gets the string defining the lower bound of this range, if any. */
327
336
string getLower ( ) { result = lower }
328
337
329
338
/**
@@ -465,11 +474,13 @@ class RegExpEscape extends RegExpNormalChar {
465
474
result = this .getUnicode ( )
466
475
}
467
476
477
+ /** Holds if this terms name is given by the part following the escape character. */
468
478
predicate isIdentityEscape ( ) { not this .getUnescaped ( ) in [ "n" , "r" , "t" , "f" ] }
469
479
470
480
override string getPrimaryQLClass ( ) { result = "RegExpEscape" }
471
481
472
- string getUnescaped ( ) { result = this .getText ( ) .suffix ( 1 ) }
482
+ /** Gets the part of the term following the escape character. That is e.g. "w" if the term is "\w". */
483
+ private string getUnescaped ( ) { result = this .getText ( ) .suffix ( 1 ) }
473
484
474
485
/**
475
486
* Gets the text for this escape. That is e.g. "\w".
@@ -536,15 +547,8 @@ private int toHex(string hex) {
536
547
* ```
537
548
*/
538
549
class RegExpCharacterClassEscape extends RegExpEscape {
539
- // string value;
540
- RegExpCharacterClassEscape ( ) {
541
- // value = re.getText().substring(start + 1, end) and
542
- // value in ["d", "D", "s", "S", "w", "W"]
543
- this .getValue ( ) in [ "d" , "D" , "s" , "S" , "w" , "W" ]
544
- }
550
+ RegExpCharacterClassEscape ( ) { this .getValue ( ) in [ "d" , "D" , "s" , "S" , "w" , "W" ] }
545
551
546
- /** Gets the name of the character class; for example, `w` for `\w`. */
547
- // override string getValue() { result = value }
548
552
override RegExpTerm getChild ( int i ) { none ( ) }
549
553
550
554
override string getPrimaryQLClass ( ) { result = "RegExpCharacterClassEscape" }
@@ -563,10 +567,13 @@ class RegExpCharacterClassEscape extends RegExpEscape {
563
567
class RegExpCharacterClass extends RegExpTerm , TRegExpCharacterClass {
564
568
RegExpCharacterClass ( ) { this = TRegExpCharacterClass ( re , start , end ) }
565
569
570
+ /** Holds if this character class is inverted, matching the opposite of its content. */
566
571
predicate isInverted ( ) { re .getChar ( start + 1 ) = "^" }
567
572
573
+ /** Gets the `i`th char inside this charater class. */
568
574
string getCharThing ( int i ) { result = re .getChar ( i + start ) }
569
575
576
+ /** Holds if this character class can match anything. */
570
577
predicate isUniversalClass ( ) {
571
578
// [^]
572
579
this .isInverted ( ) and not exists ( this .getAChild ( ) )
@@ -620,6 +627,7 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
620
627
re .charRange ( _, start , lower_end , upper_start , end )
621
628
}
622
629
630
+ /** Holds if this range goes from `lo` to `hi`, in effect is `lo-hi`. */
623
631
predicate isRange ( string lo , string hi ) {
624
632
lo = re .getText ( ) .substring ( start , lower_end ) and
625
633
hi = re .getText ( ) .substring ( upper_start , end )
@@ -653,8 +661,13 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
653
661
class RegExpNormalChar extends RegExpTerm , TRegExpNormalChar {
654
662
RegExpNormalChar ( ) { this = TRegExpNormalChar ( re , start , end ) }
655
663
664
+ /**
665
+ * Holds if this constant represents a valid Unicode character (as opposed
666
+ * to a surrogate code point that does not correspond to a character by itself.)
667
+ */
656
668
predicate isCharacter ( ) { any ( ) }
657
669
670
+ /** Gets the string representation of the char matched by this term. */
658
671
string getValue ( ) { result = re .getText ( ) .substring ( start , end ) }
659
672
660
673
override RegExpTerm getChild ( int i ) { none ( ) }
@@ -684,15 +697,15 @@ class RegExpConstant extends RegExpTerm {
684
697
qstart <= start and end <= qend
685
698
) and
686
699
value = this .( RegExpNormalChar ) .getValue ( )
687
- // This will never hold
688
- // or
689
- // this = TRegExpSpecialChar(re, start, end) and
690
- // re.inCharSet(start) and
691
- // value = this.(RegExpSpecialChar).getChar()
692
700
}
693
701
702
+ /**
703
+ * Holds if this constant represents a valid Unicode character (as opposed
704
+ * to a surrogate code point that does not correspond to a character by itself.)
705
+ */
694
706
predicate isCharacter ( ) { any ( ) }
695
707
708
+ /** Gets the string matched by this constant term. */
696
709
string getValue ( ) { result = value }
697
710
698
711
override RegExpTerm getChild ( int i ) { none ( ) }
@@ -731,10 +744,6 @@ class RegExpGroup extends RegExpTerm, TRegExpGroup {
731
744
/** Gets the name of this capture group, if any. */
732
745
string getName ( ) { result = re .getGroupName ( start , end ) }
733
746
734
- predicate isCharacter ( ) { any ( ) }
735
-
736
- string getValue ( ) { result = re .getText ( ) .substring ( start , end ) }
737
-
738
747
override RegExpTerm getChild ( int i ) {
739
748
result .getRegex ( ) = re and
740
749
i = 0 and
@@ -762,8 +771,13 @@ class RegExpSpecialChar extends RegExpTerm, TRegExpSpecialChar {
762
771
re .specialCharacter ( start , end , char )
763
772
}
764
773
774
+ /**
775
+ * Holds if this constant represents a valid Unicode character (as opposed
776
+ * to a surrogate code point that does not correspond to a character by itself.)
777
+ */
765
778
predicate isCharacter ( ) { any ( ) }
766
779
780
+ /** Gets the char for this term. */
767
781
string getChar ( ) { result = char }
768
782
769
783
override RegExpTerm getChild ( int i ) { none ( ) }
@@ -828,8 +842,6 @@ class RegExpCaret extends RegExpSpecialChar {
828
842
class RegExpZeroWidthMatch extends RegExpGroup {
829
843
RegExpZeroWidthMatch ( ) { re .zeroWidthMatch ( start , end ) }
830
844
831
- override predicate isCharacter ( ) { any ( ) }
832
-
833
845
override RegExpTerm getChild ( int i ) { none ( ) }
834
846
835
847
override string getPrimaryQLClass ( ) { result = "RegExpZeroWidthMatch" }
0 commit comments