Commit d809fd0
committed
Improve parser's one-extra-token lookahead mechanism.
There are a couple of places in our grammar that fail to be strict LALR(1),
by requiring more than a single token of lookahead to decide what to do.
Up to now we've dealt with that by using a filter between the lexer and
parser that merges adjacent tokens into one in the places where two tokens
of lookahead are necessary. But that creates a number of user-visible
anomalies, for instance that you can't name a CTE "ordinality" because
"WITH ordinality AS ..." triggers folding of WITH and ORDINALITY into one
token. I realized that there's a better way.
In this patch, we still do the lookahead basically as before, but we never
merge the second token into the first; we replace just the first token by
a special lookahead symbol when one of the lookahead pairs is seen.
This requires a couple extra productions in the grammar, but it involves
fewer special tokens, so that the grammar tables come out a bit smaller
than before. The filter logic is no slower than before, perhaps a bit
faster.
I also fixed the filter logic so that when backing up after a lookahead,
the current token's terminator is correctly restored; this eliminates some
weird behavior in error message issuance, as is shown by the one change in
existing regression test outputs.
I believe that this patch entirely eliminates odd behaviors caused by
lookahead for WITH. It doesn't really improve the situation for NULLS
followed by FIRST/LAST unfortunately: those sequences still act like a
reserved word, even though there are cases where they should be seen as two
ordinary identifiers, eg "SELECT nulls first FROM ...". I experimented
with additional grammar hacks but couldn't find any simple solution for
that. Still, this is better than before, and it seems much more likely
that we *could* somehow solve the NULLS case on the basis of this filter
behavior than the previous one.1 parent 23a7835 commit d809fd0
File tree
8 files changed
+173
-113
lines changed- src
- backend/parser
- include/parser
- interfaces/ecpg/preproc
- test/regress
- expected
- sql
8 files changed
+173
-113
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
633 | 633 | | |
634 | 634 | | |
635 | 635 | | |
636 | | - | |
| 636 | + | |
637 | 637 | | |
638 | | - | |
| 638 | + | |
639 | 639 | | |
640 | 640 | | |
641 | 641 | | |
| |||
873 | 873 | | |
874 | 874 | | |
875 | 875 | | |
| 876 | + | |
876 | 877 | | |
877 | 878 | | |
878 | 879 | | |
| |||
6673 | 6674 | | |
6674 | 6675 | | |
6675 | 6676 | | |
6676 | | - | |
6677 | | - | |
| 6677 | + | |
| 6678 | + | |
6678 | 6679 | | |
6679 | 6680 | | |
6680 | 6681 | | |
| |||
8923 | 8924 | | |
8924 | 8925 | | |
8925 | 8926 | | |
8926 | | - | |
| 8927 | + | |
8927 | 8928 | | |
8928 | 8929 | | |
8929 | 8930 | | |
| |||
8933 | 8934 | | |
8934 | 8935 | | |
8935 | 8936 | | |
8936 | | - | |
| 8937 | + | |
8937 | 8938 | | |
8938 | 8939 | | |
8939 | 8940 | | |
| |||
8943 | 8944 | | |
8944 | 8945 | | |
8945 | 8946 | | |
8946 | | - | |
| 8947 | + | |
8947 | 8948 | | |
8948 | 8949 | | |
8949 | 8950 | | |
| |||
8953 | 8954 | | |
8954 | 8955 | | |
8955 | 8956 | | |
8956 | | - | |
| 8957 | + | |
8957 | 8958 | | |
8958 | 8959 | | |
8959 | 8960 | | |
| |||
8981 | 8982 | | |
8982 | 8983 | | |
8983 | 8984 | | |
| 8985 | + | |
| 8986 | + | |
| 8987 | + | |
| 8988 | + | |
| 8989 | + | |
8984 | 8990 | | |
8985 | 8991 | | |
8986 | 8992 | | |
| |||
9891 | 9897 | | |
9892 | 9898 | | |
9893 | 9899 | | |
| 9900 | + | |
| 9901 | + | |
9894 | 9902 | | |
9895 | 9903 | | |
9896 | 9904 | | |
| |||
9900 | 9908 | | |
9901 | 9909 | | |
9902 | 9910 | | |
| 9911 | + | |
| 9912 | + | |
| 9913 | + | |
| 9914 | + | |
| 9915 | + | |
| 9916 | + | |
| 9917 | + | |
9903 | 9918 | | |
9904 | 9919 | | |
9905 | 9920 | | |
| |||
10601 | 10616 | | |
10602 | 10617 | | |
10603 | 10618 | | |
10604 | | - | |
| 10619 | + | |
10605 | 10620 | | |
10606 | 10621 | | |
10607 | 10622 | | |
| |||
11057 | 11072 | | |
11058 | 11073 | | |
11059 | 11074 | | |
11060 | | - | |
| 11075 | + | |
11061 | 11076 | | |
11062 | 11077 | | |
11063 | 11078 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
64 | 64 | | |
65 | 65 | | |
66 | 66 | | |
67 | | - | |
| 67 | + | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
| 87 | + | |
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| |||
93 | 93 | | |
94 | 94 | | |
95 | 95 | | |
| 96 | + | |
96 | 97 | | |
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
101 | | - | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
102 | 108 | | |
103 | 109 | | |
104 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
105 | 119 | | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
| 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 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
112 | 156 | | |
113 | 157 | | |
114 | 158 | | |
115 | | - | |
116 | | - | |
117 | 159 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
124 | | - | |
125 | | - | |
126 | | - | |
127 | | - | |
128 | | - | |
| 160 | + | |
129 | 161 | | |
130 | 162 | | |
131 | 163 | | |
132 | 164 | | |
133 | 165 | | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 166 | + | |
141 | 167 | | |
142 | 168 | | |
143 | 169 | | |
144 | | - | |
145 | | - | |
146 | 170 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
| 171 | + | |
158 | 172 | | |
159 | 173 | | |
160 | 174 | | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | 175 | | |
165 | 176 | | |
166 | 177 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
| 50 | + | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 45 | + | |
| 46 | + | |
49 | 47 | | |
50 | 48 | | |
51 | 49 | | |
| |||
0 commit comments