Skip to content

Commit ec937d0

Browse files
committed
Align ECPG lexer more closely with the core and psql lexers.
Make a bunch of basically-cosmetic changes to reduce the diffs between the flex rules in scan.l, psqlscan.l, and pgc.l. Reorder some code, adjust a lot of whitespace, sync some comments, make use of flex start condition scopes to do that. There are a few non-cosmetic changes in the ECPG lexer: * Bring over the decimalfail rule (and support function process_integer_literal) so that ECPG will lex "1..10" into the same tokens as the backend would. I'm not sure this makes any visible difference to users, but I'm not sure it doesn't, either. * <xdc><<EOF>> gets its own rule so as to produce a more on-point error message. * Remove duplicate <SQL>{xdstart} rule. John Naylor, with a few additional changes by me Discussion: https://postgr.es/m/CAJVSVGWGqY9YBs2EwtRUkbNv=hXkN8yRPOoD1wxE6COgvvrz5g@mail.gmail.com
1 parent d20dcea commit ec937d0

File tree

3 files changed

+594
-442
lines changed

3 files changed

+594
-442
lines changed

src/backend/parser/scan.l

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
*
77
* NOTE NOTE NOTE:
88
*
9-
* The rules in this file must be kept in sync with src/fe_utils/psqlscan.l!
9+
* The rules in this file must be kept in sync with src/fe_utils/psqlscan.l
10+
* and src/interfaces/ecpg/preproc/pgc.l!
1011
*
1112
* The rules are designed so that the scanner never has to backtrack,
1213
* in the sense that there is always a rule that can match the input
@@ -168,8 +169,8 @@ extern void core_yyset_column(int column_no, yyscan_t yyscanner);
168169
%x xc
169170
%x xd
170171
%x xh
171-
%x xe
172172
%x xq
173+
%x xe
173174
%x xdolq
174175
%x xui
175176
%x xuiend
@@ -192,7 +193,7 @@ extern void core_yyset_column(int column_no, yyscan_t yyscanner);
192193
* XXX perhaps \f (formfeed) should be treated as a newline as well?
193194
*
194195
* XXX if you change the set of whitespace characters, fix scanner_isspace()
195-
* to agree, and see also the plpgsql lexer.
196+
* to agree.
196197
*/
197198

198199
space [ \t\n\r\f]
@@ -417,32 +418,36 @@ other .
417418
yyless(2);
418419
}
419420

420-
<xc>{xcstart} {
421+
<xc>{
422+
{xcstart} {
421423
(yyextra->xcdepth)++;
422424
/* Put back any characters past slash-star; see above */
423425
yyless(2);
424426
}
425427

426-
<xc>{xcstop} {
428+
{xcstop} {
427429
if (yyextra->xcdepth <= 0)
428430
BEGIN(INITIAL);
429431
else
430432
(yyextra->xcdepth)--;
431433
}
432434

433-
<xc>{xcinside} {
435+
{xcinside} {
434436
/* ignore */
435437
}
436438

437-
<xc>{op_chars} {
439+
{op_chars} {
438440
/* ignore */
439441
}
440442

441-
<xc>\*+ {
443+
\*+ {
442444
/* ignore */
443445
}
444446

445-
<xc><<EOF>> { yyerror("unterminated /* comment"); }
447+
<<EOF>> {
448+
yyerror("unterminated /* comment");
449+
}
450+
} /* <xc> */
446451

447452
{xbstart} {
448453
/* Binary bit type.

src/fe_utils/psqlscan.l

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*
2424
* See psqlscan_int.h for additional commentary.
2525
*
26+
*
2627
* Portions Copyright (c) 1996-2018, PostgreSQL Global Development Group
2728
* Portions Copyright (c) 1994, Regents of the University of California
2829
*
@@ -39,6 +40,9 @@
3940
}
4041

4142
%{
43+
44+
/* LCOV_EXCL_START */
45+
4246
#include "fe_utils/psqlscan_int.h"
4347

4448
/*
@@ -71,8 +75,6 @@ typedef int YYSTYPE;
7175
extern int psql_yyget_column(yyscan_t yyscanner);
7276
extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
7377

74-
/* LCOV_EXCL_START */
75-
7678
%}
7779

7880
%option reentrant
@@ -128,8 +130,8 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
128130
%x xc
129131
%x xd
130132
%x xh
131-
%x xe
132133
%x xq
134+
%x xe
133135
%x xdolq
134136
%x xui
135137
%x xuiend
@@ -151,7 +153,7 @@ extern void psql_yyset_column(int column_no, yyscan_t yyscanner);
151153
* XXX perhaps \f (formfeed) should be treated as a newline as well?
152154
*
153155
* XXX if you change the set of whitespace characters, fix scanner_isspace()
154-
* to agree, and see also the plpgsql lexer.
156+
* to agree.
155157
*/
156158

157159
space [ \t\n\r\f]
@@ -402,32 +404,34 @@ other .
402404
ECHO;
403405
}
404406

405-
<xc>{xcstart} {
407+
<xc>{
408+
{xcstart} {
406409
cur_state->xcdepth++;
407410
/* Put back any characters past slash-star; see above */
408411
yyless(2);
409412
ECHO;
410413
}
411414

412-
<xc>{xcstop} {
415+
{xcstop} {
413416
if (cur_state->xcdepth <= 0)
414417
BEGIN(INITIAL);
415418
else
416419
cur_state->xcdepth--;
417420
ECHO;
418421
}
419422

420-
<xc>{xcinside} {
423+
{xcinside} {
421424
ECHO;
422425
}
423426

424-
<xc>{op_chars} {
427+
{op_chars} {
425428
ECHO;
426429
}
427430

428-
<xc>\*+ {
431+
\*+ {
429432
ECHO;
430433
}
434+
} /* <xc> */
431435

432436
{xbstart} {
433437
BEGIN(xb);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy