2
2
* Module for parsing access paths from CSV models, both the identifying access path used
3
3
* by dynamic languages, and the input/output specifications for summary steps.
4
4
*
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
6
6
* (which does not use the shared data flow libraries).
7
7
*/
8
8
@@ -15,36 +15,36 @@ module AccessPath {
15
15
}
16
16
}
17
17
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
+
18
26
/**
19
27
* A string that occurs as an access path (either identifying or input/output spec)
20
28
* which might be relevant for this database.
21
29
*/
22
30
class 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
-
31
31
/** Holds if this string is not a syntactically valid access path. */
32
32
predicate hasSyntaxError ( ) {
33
33
// If the lengths match, all characters must haven been included in a token
34
34
// or seen by the `.` lookahead pattern.
35
35
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
37
37
}
38
38
39
39
/** Gets the `n`th token on the access path (if there are no syntax errors). */
40
40
AccessPathToken getToken ( int n ) {
41
- result = this . getRawToken ( n ) and
41
+ result = getRawToken ( this , n ) and
42
42
not hasSyntaxError ( )
43
43
}
44
44
45
45
/** Gets the number of tokens on the path (if there are no syntax errors). */
46
46
int getNumToken ( ) {
47
- result = count ( int n | exists ( this . getRawToken ( n ) ) ) and
47
+ result = count ( int n | exists ( getRawToken ( this , n ) ) ) and
48
48
not hasSyntaxError ( )
49
49
}
50
50
@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
56
56
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
57
57
*/
58
58
class AccessPathToken extends string {
59
- AccessPathToken ( ) { this = any ( AccessPath path ) . getRawToken ( _) }
59
+ AccessPathToken ( ) { this = getRawToken ( any ( AccessPath path ) , _) }
60
60
61
61
private string getPart ( int part ) {
62
62
result = this .regexpCapture ( "([^\\[]+)(?:\\[([^\\]]*)\\])?" , part )
0 commit comments