4
4
* procedural language
5
5
*
6
6
* IDENTIFICATION
7
- * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.4 2000/06/20 16:40:10 petere Exp $
7
+ * $Header: /cvsroot/pgsql/src/pl/plpgsql/src/Attic/scan.l,v 1.5 2000/08/22 14:59:28 tgl Exp $
8
8
*
9
9
* This software is copyrighted by Jan Wieck - Hamburg.
10
10
*
@@ -40,11 +40,13 @@ static char*plpgsql_source;
40
40
static int plpgsql_bytes_left;
41
41
static int scanner_functype;
42
42
static int scanner_typereported;
43
+
43
44
int plpgsql_SpaceScanned =0 ;
44
45
45
46
extern int yylineno;
46
47
47
48
static void plpgsql_input (char *buf,int *result,int max);
49
+
48
50
#define YY_INPUT (buf,res,max )plpgsql_input(buf, &res, max)
49
51
#define YY_NO_UNPUT
50
52
%}
@@ -74,37 +76,38 @@ WC[[:alnum:]_"]
74
76
* functions type (T_FUNCTION or T_TRIGGER)
75
77
* ----------
76
78
*/
77
- if (!scanner_typereported) {
78
- scanner_typereported =1 ;
79
- return scanner_functype;
80
- }
79
+ if (!scanner_typereported)
80
+ {
81
+ scanner_typereported =1 ;
82
+ return scanner_functype;
83
+ }
81
84
82
85
/* ----------
83
86
* The keyword rules
84
87
* ----------
85
88
*/
86
- :={return K_ASSIGN;}
87
- ={return K_ASSIGN;}
89
+ := {return K_ASSIGN;}
90
+ = {return K_ASSIGN;}
88
91
\.\. {return K_DOTDOT;}
89
92
alias{return K_ALIAS;}
90
93
begin{return K_BEGIN;}
91
94
bpchar{return T_BPCHAR;}
92
95
char{return T_CHAR;}
93
- constant{return K_CONSTANT; }
96
+ constant{return K_CONSTANT;}
94
97
debug{return K_DEBUG;}
95
98
declare{return K_DECLARE;}
96
99
default{return K_DEFAULT;}
97
100
else{return K_ELSE;}
98
- end{return K_END;}
99
- exception{return K_EXCEPTION; }
101
+ end {return K_END;}
102
+ exception{return K_EXCEPTION;}
100
103
exit{return K_EXIT;}
101
- for{return K_FOR;}
104
+ for {return K_FOR;}
102
105
from{return K_FROM;}
103
- if{return K_IF;}
104
- in{return K_IN;}
106
+ if {return K_IF;}
107
+ in {return K_IN;}
105
108
into{return K_INTO;}
106
109
loop{return K_LOOP;}
107
- not{return K_NOT;}
110
+ not {return K_NOT;}
108
111
notice{return K_NOTICE;}
109
112
null{return K_NULL;}
110
113
perform{return K_PERFORM;}
@@ -115,7 +118,7 @@ return{ return K_RETURN;}
115
118
reverse{return K_REVERSE;}
116
119
select{return K_SELECT;}
117
120
then{return K_THEN;}
118
- to{return K_TO;}
121
+ to {return K_TO;}
119
122
type{return K_TYPE;}
120
123
varchar{return T_VARCHAR;}
121
124
when{return K_WHEN;}
@@ -143,13 +146,13 @@ dump{ return O_DUMP;}
143
146
* Ignore whitespaces but remember this happened
144
147
* ----------
145
148
*/
146
- [\t\n ]+ { plpgsql_SpaceScanned =1 ;}
149
+ [\t\r\ n ]+ { plpgsql_SpaceScanned =1 ;}
147
150
148
151
/* ----------
149
152
* Eat up comments
150
153
* ----------
151
154
*/
152
- --[^ \n ]* ;
155
+ --[^ \r\ n ]* ;
153
156
\/\* { start_lineno = yylineno;
154
157
BEGIN IN_COMMENT;
155
158
}
@@ -188,22 +191,25 @@ dump{ return O_DUMP;}
188
191
189
192
%%
190
193
191
- int yywrap ()
194
+ int
195
+ yywrap ()
192
196
{
193
197
return 1 ;
194
198
}
195
199
196
200
197
- static void plpgsql_input (char *buf,int *result,int max)
201
+ static void
202
+ plpgsql_input (char *buf,int *result,int max)
198
203
{
199
- int n = max;
200
- if (n > plpgsql_bytes_left) {
204
+ int n = max;
205
+
206
+ if (n > plpgsql_bytes_left)
201
207
n = plpgsql_bytes_left;
202
- }
203
208
204
- if (n ==0 ) {
209
+ if (n ==0 )
210
+ {
205
211
*result = YY_NULL;
206
- return ;
212
+ return ;
207
213
}
208
214
209
215
*result = n;
@@ -213,18 +219,29 @@ static void plpgsql_input(char *buf, int *result, int max)
213
219
}
214
220
215
221
216
- void plpgsql_setinput (char *source,int functype)
222
+ void
223
+ plpgsql_setinput (char *source,int functype)
217
224
{
218
225
yyrestart (NULL );
219
226
yylineno =1 ;
220
227
221
228
plpgsql_source = source;
229
+
230
+ /*----------
231
+ * Hack: skip any initial newline, so that in the common coding layout
232
+ *CREATE FUNCTION ... AS '
233
+ *code body
234
+ *' LANGUAGE 'plpgsql';
235
+ * we will think "line 1" is what the programmer thinks of as line 1.
236
+ *----------
237
+ */
238
+ if (*plpgsql_source ==' \r ' )
239
+ plpgsql_source++;
222
240
if (*plpgsql_source ==' \n ' )
223
241
plpgsql_source++;
242
+
224
243
plpgsql_bytes_left =strlen (plpgsql_source);
225
244
226
245
scanner_functype = functype;
227
246
scanner_typereported =0 ;
228
247
}
229
-
230
-