Repository navigation
Commit dd03d6f
authored
fix: give every parsed object a node spanning its source (#2870)
* fix: give arithmetic expressions an AST node
prattArithRest builds operator expressions in plain Java, outside any
production, so JJTree never opened a node for them and `CURRENT_DATE - 7`
or `a || b` had no source range. Each expression the loop builds is now
linked to a node from the token its operand chain starts at to the last
token consumed. The node stays out of the tree, so the operands' nodes
keep their place.
* refactor: let every statement class carry an AST node
The statement classes that implemented Statement alone now extend
ASTNodeAccessImpl, as Select and Import already did, so a parsed
statement can hold the node that records its source range. Nothing
links them yet.
* fix: give every parsed object a node spanning its source
Objects no grammar rule opens a node for, such as a column's table
qualifier, a WHEN clause, nested AND/OR, IS NULL, BETWEEN, parameter
lists, data types, ORDER BY elements and statements, are linked to a
RangeNode: a node outside the parse tree that records the object's first
and last token. getASTRoot() returns the same tree, and no tree node
gains or changes its value.
Ranges that missed text their object prints now cover it: a statement's
WITH, Oracle PRIOR and (+), LIMIT ... BY, sequence options, IF ... ELSE
and merged adjacent literals. A string literal no longer takes the node
of the primary expression around it. Comments get positions, so an
Oracle hint has a range too. getParent() returns null instead of
throwing once it runs out of tree.
ASTNodeCoverageTest parses the test resources' SQL and requires every
ASTNodeAccess object to have a node of at least one character, inside
its holder's range, never partly overlapping another, holding no
parser, and, for expressions and statements, covering text that parses
back to the same object.
* fix: link statements nested in others, and position every comment
Statements that never pass through SingleStatement get their node where
they are built: data-modifying CTEs, statements inside an Oracle block,
CREATE SCHEMA elements, CREATE TABLE ... AS EXECUTE and the GRANT or
REVOKE of ALTER DEFAULT PRIVILEGES. An IF statement's range takes in the
semicolon it prints.
A RangeNode that widens a tree node answers its children, id and dump
too, so a WITH statement's node still shows the tree beneath it.
Comments are positioned in one backwards pass over the recorded match
begins, and comments before the end of input are positioned once
parsing ends, since the end-of-file token gets no token action.
Values in a primary expression, string literals, expression lists and
row patterns get a RangeNode only once something wraps them, so a
production's own tree node is the only node most of them get. On a
20,000-row INSERT ... VALUES this cuts the added allocation from 12.9%
to 3.2%.
The coverage test parses the Oracle tests in the Oracle dialect, checks
that getParent() encloses each range, and runs its checks over the
statements above, which the test corpus does not contain.
* test: split the coverage walk to settle Codacy's PMD findings
`visit` and `checkRange` exceeded PMD's NPath threshold of 200, so the
container walk and the parent check move into methods of their own.
`isHeld` compares with `==` on purpose: a getter that answers a new
object on every call computes its child rather than holding it.
* perf: create the deque of NOT tokens only for a NOT condition
`Condition()` created a deque for the tokens of a leading `NOT` on every
call, though few conditions have one. Each empty `ArrayDeque` allocates
its 16-slot array up front, so parsing `performance.sql` allocated
585 KB more per parse. The deque is now created at the first `NOT`.
* refactor: keep RangeNode internal to the parser package
Only the generated parser creates a `RangeNode`, and callers see it as
the `Node` that `getASTNode()` returns. Keeping the class package-private
leaves its design free to change before a release.1 parent df97e40 commit dd03d6f
126 files changed
Lines changed: 1322 additions & 326 deletions
File tree
- src
- main
- java/net/sf/jsqlparser
- parser
- statement
- alter
- database
- schema
- sequence
- analyze
- comment
- create
- accessmethod
- collation
- database
- domain
- event
- extension
- index
- macro
- policy
- publication
- rule
- schema
- sequence
- statistics
- subscription
- synonym
- tablespace
- table
- textsearch
- trigger
- type
- user
- view
- delete
- drop
- execute
- export
- foreign
- grant
- insert
- load
- lock
- merge
- notify
- oracle
- refresh
- reindex
- role
- securitylabel
- select
- show
- truncate
- update
- upsert
- jjtree/net/sf/jsqlparser/parser
- test/java/net/sf/jsqlparser
- parser
- statement/select
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
74 | 78 | | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
| 79 | + | |
81 | 80 | | |
82 | 81 | | |
83 | 82 | | |
84 | | - | |
85 | | - | |
| 83 | + | |
| 84 | + | |
86 | 85 | | |
87 | 86 | | |
88 | | - | |
89 | | - | |
| 87 | + | |
90 | 88 | | |
91 | 89 | | |
92 | 90 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
51 | 54 | | |
52 | 55 | | |
53 | 56 | | |
| |||
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
110 | 145 | | |
111 | 146 | | |
112 | 147 | | |
| |||
200 | 235 | | |
201 | 236 | | |
202 | 237 | | |
| 238 | + | |
203 | 239 | | |
204 | 240 | | |
205 | 241 | | |
| |||
441 | 477 | | |
442 | 478 | | |
443 | 479 | | |
| 480 | + | |
444 | 481 | | |
445 | 482 | | |
446 | 483 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | | - | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | | - | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | | - | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
12 | 14 | | |
13 | 15 | | |
14 | 16 | | |
15 | 17 | | |
16 | | - | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | | - | |
| 29 | + | |
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | | - | |
| 25 | + | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
| |||
0 commit comments