22 * Module for parsing access paths from CSV models, both the identifying access path used
33 * by dynamic languages, and the input/output specifications for summary steps.
44 *
5- * This file is used by shared data flow library and by the JavaScript libraries
5+ * This file is used by the shared data flow library and by the JavaScript libraries
66 * (which does not use the shared data flow libraries).
77 */
88
@@ -15,36 +15,36 @@ module AccessPath {
1515 }
1616}
1717
18+ /** Gets the `n`th token on the access path as a string. */
19+ private string getRawToken ( AccessPath path , int n ) {
20+ // Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
21+ // Instead use regexpFind to match valid tokens, and supplement with a final length
22+ // check to ensure all characters were included in a token.
23+ result = path .regexpFind ( "\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)" , n , _)
24+ }
25+
1826/**
1927 * A string that occurs as an access path (either identifying or input/output spec)
2028 * which might be relevant for this database.
2129 */
2230class AccessPath extends string instanceof AccessPath:: Range {
23- /** Gets the `n`th token on the access path as a string. */
24- string getRawToken ( int n ) {
25- // Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
26- // Instead use regexpFind to match valid tokens, and supplement with a final length
27- // check to ensure all characters were included in a token.
28- result = this .regexpFind ( "\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)" , n , _)
29- }
30-
3131 /** Holds if this string is not a syntactically valid access path. */
3232 predicate hasSyntaxError ( ) {
3333 // If the lengths match, all characters must haven been included in a token
3434 // or seen by the `.` lookahead pattern.
3535 this != "" and
36- not this .length ( ) = sum ( int n | | getRawToken ( n ) .length ( ) + 1 ) - 1
36+ not this .length ( ) = sum ( int n | | getRawToken ( this , n ) .length ( ) + 1 ) - 1
3737 }
3838
3939 /** Gets the `n`th token on the access path (if there are no syntax errors). */
4040 AccessPathToken getToken ( int n ) {
41- result = this . getRawToken ( n ) and
41+ result = getRawToken ( this , n ) and
4242 not hasSyntaxError ( )
4343 }
4444
4545 /** Gets the number of tokens on the path (if there are no syntax errors). */
4646 int getNumToken ( ) {
47- result = count ( int n | exists ( this . getRawToken ( n ) ) ) and
47+ result = count ( int n | exists ( getRawToken ( this , n ) ) ) and
4848 not hasSyntaxError ( )
4949 }
5050
@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
5656 * An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
5757 */
5858class AccessPathToken extends string {
59- AccessPathToken ( ) { this = any ( AccessPath path ) . getRawToken ( _) }
59+ AccessPathToken ( ) { this = getRawToken ( any ( AccessPath path ) , _) }
6060
6161 private string getPart ( int part ) {
6262 result = this .regexpCapture ( "([^\\[]+)(?:\\[([^\\]]*)\\])?" , part )
0 commit comments