Shared: fix qldoc and move getRawToken to top-level

This commit is contained in:
Asger Feldthaus
2022-02-10 14:27:55 +01:00
parent c189df2341
commit be63cf7049
2 changed files with 14 additions and 14 deletions

View File

@@ -2,7 +2,7 @@
* Module for parsing access paths from CSV models, both the identifying access path used
* by dynamic languages, and the input/output specifications for summary steps.
*
* This file is used by shared data flow library and by the JavaScript libraries
* This file is used by the shared data flow library and by the JavaScript libraries
* (which does not use the shared data flow libraries).
*/
@@ -15,36 +15,36 @@ module AccessPath {
}
}
/** Gets the `n`th token on the access path as a string. */
private string getRawToken(AccessPath path, int n) {
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
// Instead use regexpFind to match valid tokens, and supplement with a final length
// check to ensure all characters were included in a token.
result = path.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
}
/**
* A string that occurs as an access path (either identifying or input/output spec)
* which might be relevant for this database.
*/
class AccessPath extends string instanceof AccessPath::Range {
/** Gets the `n`th token on the access path as a string. */
string getRawToken(int n) {
// Avoid splitting by '.' since tokens may contain dots, e.g. `Field[foo.Bar.x]`.
// Instead use regexpFind to match valid tokens, and supplement with a final length
// check to ensure all characters were included in a token.
result = this.regexpFind("\\w+(?:\\[[^\\]]*\\])?(?=\\.|$)", n, _)
}
/** Holds if this string is not a syntactically valid access path. */
predicate hasSyntaxError() {
// If the lengths match, all characters must haven been included in a token
// or seen by the `.` lookahead pattern.
this != "" and
not this.length() = sum(int n | | getRawToken(n).length() + 1) - 1
not this.length() = sum(int n | | getRawToken(this, n).length() + 1) - 1
}
/** Gets the `n`th token on the access path (if there are no syntax errors). */
AccessPathToken getToken(int n) {
result = this.getRawToken(n) and
result = getRawToken(this, n) and
not hasSyntaxError()
}
/** Gets the number of tokens on the path (if there are no syntax errors). */
int getNumToken() {
result = count(int n | exists(this.getRawToken(n))) and
result = count(int n | exists(getRawToken(this, n))) and
not hasSyntaxError()
}
@@ -56,7 +56,7 @@ class AccessPath extends string instanceof AccessPath::Range {
* An access part token such as `Argument[1]` or `ReturnValue`, appearing in one or more access paths.
*/
class AccessPathToken extends string {
AccessPathToken() { this = any(AccessPath path).getRawToken(_) }
AccessPathToken() { this = getRawToken(any(AccessPath path), _) }
private string getPart(int part) {
result = this.regexpCapture("([^\\[]+)(?:\\[([^\\]]*)\\])?", part)

View File

@@ -892,7 +892,7 @@ module Private {
/** Holds if component `c` of specification `spec` cannot be parsed. */
predicate invalidSpecComponent(AccessPath spec, string c) {
c = spec.getRawToken(_) and
c = spec.getToken(_) and
not exists(interpretComponent(c))
}