@@ -49,6 +49,7 @@ newtype TRegExpParent =
4949 * or another regular expression term.
5050 */
5151class RegExpParent extends TRegExpParent {
52+ /** Gets a textual representation of this element. */
5253 string toString ( ) { result = "RegExpParent" }
5354
5455 /** Gets the `i`th child term. */
@@ -72,14 +73,18 @@ class RegExpLiteral extends TRegExpLiteral, RegExpParent {
7273
7374 override RegExpTerm getChild ( int i ) { i = 0 and result .getRegex ( ) = re and result .isRootTerm ( ) }
7475
76+ /** Holds if dot, `.`, matches all characters, including newlines. */
7577 predicate isDotAll ( ) { re .getAMode ( ) = "DOTALL" }
7678
79+ /** Holds if this regex matching is case-insensitive for this regex. */
7780 predicate isIgnoreCase ( ) { re .getAMode ( ) = "IGNORECASE" }
7881
82+ /** Get a string representing all modes for this regex. */
7983 string getFlags ( ) { result = concat ( string mode | mode = re .getAMode ( ) | mode , " | " ) }
8084
8185 override Regex getRegex ( ) { result = re }
8286
87+ /** Gets the primary QL class for this regex. */
8388 string getPrimaryQLClass ( ) { result = "RegExpLiteral" }
8489}
8590
@@ -246,8 +251,10 @@ class RegExpQuantifier extends RegExpTerm, TRegExpQuantifier {
246251 result .getEnd ( ) = part_end
247252 }
248253
254+ /** Hols if this term may match an unlimited number of times. */
249255 predicate mayRepeatForever ( ) { may_repeat_forever = true }
250256
257+ /** Gets the qualifier for this term. That is e.g "?" for "a?". */
251258 string getQualifier ( ) { result = re .getText ( ) .substring ( part_end , end ) }
252259
253260 override string getPrimaryQLClass ( ) { result = "RegExpQuantifier" }
@@ -322,8 +329,10 @@ class RegExpRange extends RegExpQuantifier {
322329
323330 RegExpRange ( ) { re .multiples ( part_end , end , lower , upper ) }
324331
332+ /** Gets the string defining the upper bound of this range, if any. */
325333 string getUpper ( ) { result = upper }
326334
335+ /** Gets the string defining the lower bound of this range, if any. */
327336 string getLower ( ) { result = lower }
328337
329338 /**
@@ -465,11 +474,13 @@ class RegExpEscape extends RegExpNormalChar {
465474 result = this .getUnicode ( )
466475 }
467476
477+ /** Holds if this terms name is given by the part following the escape character. */
468478 predicate isIdentityEscape ( ) { not this .getUnescaped ( ) in [ "n" , "r" , "t" , "f" ] }
469479
470480 override string getPrimaryQLClass ( ) { result = "RegExpEscape" }
471481
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 ) }
473484
474485 /**
475486 * Gets the text for this escape. That is e.g. "\w".
@@ -536,15 +547,8 @@ private int toHex(string hex) {
536547 * ```
537548 */
538549class 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" ] }
545551
546- /** Gets the name of the character class; for example, `w` for `\w`. */
547- // override string getValue() { result = value }
548552 override RegExpTerm getChild ( int i ) { none ( ) }
549553
550554 override string getPrimaryQLClass ( ) { result = "RegExpCharacterClassEscape" }
@@ -563,10 +567,13 @@ class RegExpCharacterClassEscape extends RegExpEscape {
563567class RegExpCharacterClass extends RegExpTerm , TRegExpCharacterClass {
564568 RegExpCharacterClass ( ) { this = TRegExpCharacterClass ( re , start , end ) }
565569
570+ /** Holds if this character class is inverted, matching the opposite of its content. */
566571 predicate isInverted ( ) { re .getChar ( start + 1 ) = "^" }
567572
573+ /** Gets the `i`th char inside this charater class. */
568574 string getCharThing ( int i ) { result = re .getChar ( i + start ) }
569575
576+ /** Holds if this character class can match anything. */
570577 predicate isUniversalClass ( ) {
571578 // [^]
572579 this .isInverted ( ) and not exists ( this .getAChild ( ) )
@@ -620,6 +627,7 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
620627 re .charRange ( _, start , lower_end , upper_start , end )
621628 }
622629
630+ /** Holds if this range goes from `lo` to `hi`, in effect is `lo-hi`. */
623631 predicate isRange ( string lo , string hi ) {
624632 lo = re .getText ( ) .substring ( start , lower_end ) and
625633 hi = re .getText ( ) .substring ( upper_start , end )
@@ -653,8 +661,13 @@ class RegExpCharacterRange extends RegExpTerm, TRegExpCharacterRange {
653661class RegExpNormalChar extends RegExpTerm , TRegExpNormalChar {
654662 RegExpNormalChar ( ) { this = TRegExpNormalChar ( re , start , end ) }
655663
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+ */
656668 predicate isCharacter ( ) { any ( ) }
657669
670+ /** Gets the string representation of the char matched by this term. */
658671 string getValue ( ) { result = re .getText ( ) .substring ( start , end ) }
659672
660673 override RegExpTerm getChild ( int i ) { none ( ) }
@@ -684,15 +697,15 @@ class RegExpConstant extends RegExpTerm {
684697 qstart <= start and end <= qend
685698 ) and
686699 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()
692700 }
693701
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+ */
694706 predicate isCharacter ( ) { any ( ) }
695707
708+ /** Gets the string matched by this constant term. */
696709 string getValue ( ) { result = value }
697710
698711 override RegExpTerm getChild ( int i ) { none ( ) }
@@ -731,10 +744,6 @@ class RegExpGroup extends RegExpTerm, TRegExpGroup {
731744 /** Gets the name of this capture group, if any. */
732745 string getName ( ) { result = re .getGroupName ( start , end ) }
733746
734- predicate isCharacter ( ) { any ( ) }
735-
736- string getValue ( ) { result = re .getText ( ) .substring ( start , end ) }
737-
738747 override RegExpTerm getChild ( int i ) {
739748 result .getRegex ( ) = re and
740749 i = 0 and
@@ -762,8 +771,13 @@ class RegExpSpecialChar extends RegExpTerm, TRegExpSpecialChar {
762771 re .specialCharacter ( start , end , char )
763772 }
764773
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+ */
765778 predicate isCharacter ( ) { any ( ) }
766779
780+ /** Gets the char for this term. */
767781 string getChar ( ) { result = char }
768782
769783 override RegExpTerm getChild ( int i ) { none ( ) }
@@ -828,8 +842,6 @@ class RegExpCaret extends RegExpSpecialChar {
828842class RegExpZeroWidthMatch extends RegExpGroup {
829843 RegExpZeroWidthMatch ( ) { re .zeroWidthMatch ( start , end ) }
830844
831- override predicate isCharacter ( ) { any ( ) }
832-
833845 override RegExpTerm getChild ( int i ) { none ( ) }
834846
835847 override string getPrimaryQLClass ( ) { result = "RegExpZeroWidthMatch" }
0 commit comments