44 * procedural language
55 *
66 * 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 $
88 *
99 * This software is copyrighted by Jan Wieck - Hamburg.
1010 *
@@ -40,11 +40,13 @@ static char*plpgsql_source;
4040static int plpgsql_bytes_left;
4141static int scanner_functype;
4242static int scanner_typereported;
43+
4344int plpgsql_SpaceScanned =0 ;
4445
4546extern int yylineno;
4647
4748static void plpgsql_input (char *buf,int *result,int max);
49+
4850#define YY_INPUT (buf,res,max )plpgsql_input(buf, &res, max)
4951#define YY_NO_UNPUT
5052%}
@@ -74,37 +76,38 @@ WC[[:alnum:]_"]
7476 * functions type (T_FUNCTION or T_TRIGGER)
7577 * ----------
7678 */
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+ }
8184
8285/* ----------
8386 * The keyword rules
8487 * ----------
8588 */
86- :={return K_ASSIGN;}
87- ={return K_ASSIGN;}
89+ := {return K_ASSIGN;}
90+ = {return K_ASSIGN;}
8891\.\. {return K_DOTDOT;}
8992alias{return K_ALIAS;}
9093begin{return K_BEGIN;}
9194bpchar{return T_BPCHAR;}
9295char{return T_CHAR;}
93- constant{return K_CONSTANT; }
96+ constant{return K_CONSTANT;}
9497debug{return K_DEBUG;}
9598declare{return K_DECLARE;}
9699default{return K_DEFAULT;}
97100else{return K_ELSE;}
98- end{return K_END;}
99- exception{return K_EXCEPTION; }
101+ end {return K_END;}
102+ exception{return K_EXCEPTION;}
100103exit{return K_EXIT;}
101- for{return K_FOR;}
104+ for {return K_FOR;}
102105from{return K_FROM;}
103- if{return K_IF;}
104- in{return K_IN;}
106+ if {return K_IF;}
107+ in {return K_IN;}
105108into{return K_INTO;}
106109loop{return K_LOOP;}
107- not{return K_NOT;}
110+ not {return K_NOT;}
108111notice{return K_NOTICE;}
109112null{return K_NULL;}
110113perform{return K_PERFORM;}
@@ -115,7 +118,7 @@ return{ return K_RETURN;}
115118reverse{return K_REVERSE;}
116119select{return K_SELECT;}
117120then{return K_THEN;}
118- to{return K_TO;}
121+ to {return K_TO;}
119122type{return K_TYPE;}
120123varchar{return T_VARCHAR;}
121124when{return K_WHEN;}
@@ -143,13 +146,13 @@ dump{ return O_DUMP;}
143146 * Ignore whitespaces but remember this happened
144147 * ----------
145148 */
146- [\t\n ]+ { plpgsql_SpaceScanned =1 ;}
149+ [\t\r\ n ]+ { plpgsql_SpaceScanned =1 ;}
147150
148151/* ----------
149152 * Eat up comments
150153 * ----------
151154 */
152- --[^ \n ]* ;
155+ --[^ \r\ n ]* ;
153156\/\* { start_lineno = yylineno;
154157 BEGIN IN_COMMENT;
155158}
@@ -188,22 +191,25 @@ dump{ return O_DUMP;}
188191
189192%%
190193
191- int yywrap ()
194+ int
195+ yywrap ()
192196{
193197return 1 ;
194198}
195199
196200
197- static void plpgsql_input (char *buf,int *result,int max)
201+ static void
202+ plpgsql_input (char *buf,int *result,int max)
198203{
199- int n = max;
200- if (n > plpgsql_bytes_left) {
204+ int n = max;
205+
206+ if (n > plpgsql_bytes_left)
201207 n = plpgsql_bytes_left;
202- }
203208
204- if (n ==0 ) {
209+ if (n ==0 )
210+ {
205211 *result = YY_NULL;
206- return ;
212+ return ;
207213 }
208214
209215 *result = n;
@@ -213,18 +219,29 @@ static void plpgsql_input(char *buf, int *result, int max)
213219}
214220
215221
216- void plpgsql_setinput (char *source,int functype)
222+ void
223+ plpgsql_setinput (char *source,int functype)
217224{
218225yyrestart (NULL );
219226 yylineno =1 ;
220227
221228 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++;
222240if (*plpgsql_source ==' \n ' )
223241 plpgsql_source++;
242+
224243 plpgsql_bytes_left =strlen (plpgsql_source);
225244
226245 scanner_functype = functype;
227246 scanner_typereported =0 ;
228247}
229-
230-