|
7 | 7 | */
|
8 | 8 |
|
9 | 9 | import python
|
| 10 | +import semmle.python.RegexTreeView |
10 | 11 |
|
11 | 12 | private newtype TPrintAstConfiguration = MkPrintAstConfiguration()
|
12 | 13 |
|
@@ -53,6 +54,9 @@ private newtype TPrintAstNode =
|
53 | 54 | not list = any(Module mod).getBody() and
|
54 | 55 | not forall(AstNode child | child = list.getAnItem() | isNotNeeded(child)) and
|
55 | 56 | exists(list.getAnItem())
|
| 57 | + } or |
| 58 | + TRegExpTermNode(RegExpTerm term) { |
| 59 | + exists(StrConst str | term.getRootTerm() = getParsedRegExp(str) and shouldPrint(str, _)) |
56 | 60 | }
|
57 | 61 |
|
58 | 62 | /**
|
@@ -419,6 +423,42 @@ class ParameterNode extends AstElementNode {
|
419 | 423 | }
|
420 | 424 | }
|
421 | 425 |
|
| 426 | +/** |
| 427 | + * A print node for a `StrConst`. |
| 428 | + * |
| 429 | + * The string has a child, if the child is used as a regular expression, |
| 430 | + * which is the root of the regular expression. |
| 431 | + */ |
| 432 | +class StrConstNode extends AstElementNode { |
| 433 | + override StrConst element; |
| 434 | + |
| 435 | + override PrintAstNode getChild(int childIndex) { |
| 436 | + childIndex = 0 and result.(RegExpTermNode).getTerm() = getParsedRegExp(element) |
| 437 | + } |
| 438 | +} |
| 439 | + |
| 440 | +/** |
| 441 | + * A print node for a regular expression term. |
| 442 | + */ |
| 443 | +class RegExpTermNode extends TRegExpTermNode, PrintAstNode { |
| 444 | + RegExpTerm term; |
| 445 | + |
| 446 | + RegExpTermNode() { this = TRegExpTermNode(term) } |
| 447 | + |
| 448 | + /** Gets the `RegExpTerm` for this node. */ |
| 449 | + RegExpTerm getTerm() { result = term } |
| 450 | + |
| 451 | + override PrintAstNode getChild(int childIndex) { |
| 452 | + result.(RegExpTermNode).getTerm() = term.getChild(childIndex) |
| 453 | + } |
| 454 | + |
| 455 | + override string toString() { |
| 456 | + result = "[" + strictconcat(term.getPrimaryQLClass(), " | ") + "] " + term.toString() |
| 457 | + } |
| 458 | + |
| 459 | + override Location getLocation() { result = term.getLocation() } |
| 460 | +} |
| 461 | + |
422 | 462 | /**
|
423 | 463 | * Gets the `i`th child from `node` ordered by location.
|
424 | 464 | */
|
@@ -447,7 +487,7 @@ private module PrettyPrinting {
|
447 | 487 | string getQlClass(AstNode a) {
|
448 | 488 | shouldPrint(a, _) and
|
449 | 489 | (
|
450 |
| - not exists(getQlCustomClass(a)) and result = a.toString() |
| 490 | + not exists(getQlCustomClass(a)) and result = strictconcat(a.toString(), " | ") |
451 | 491 | or
|
452 | 492 | result = strictconcat(getQlCustomClass(a), " | ")
|
453 | 493 | )
|
|
0 commit comments