4 * Copyright (c) 1997-1998 Markku Rossi.
6 * Author: Markku Rossi <mtr@iki.fi>
10 * This file is part of GNU Enscript.
12 * Enscript is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 3 of the License, or
15 * (at your option) any later version.
17 * Enscript is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with Enscript. If not, see <http://www.gnu.org/licenses/>.
27 * $Id: lex.l,v 1.1.1.1 2003/03/05 07:25:52 mtr Exp $
33 static void eat_comment ();
34 static char *read_string ___P ((unsigned int *len_return));
35 static void read_regexp ___P ((Node *node));
38 real [+-]?[0-9]+\.[0-9]*|[+-]?\.[0-9]+
40 symbol [a-zA-Z_][a-zA-Z_0-9]*|\$.
44 "/*" { eat_comment (); }
48 \" { yylval.node = node_alloc (nSTRING);
49 yylval.node->u.str.data
50 = read_string (&yylval.node->u.str.len);
54 '[^\\]' { yylval.node = node_alloc (nINTEGER);
55 yylval.node->u.integer = yytext[1];
59 '\\.' { yylval.node = node_alloc (nINTEGER);
63 yylval.node->u.integer = '\n';
67 yylval.node->u.integer = '\t';
71 yylval.node->u.integer = '\v';
75 yylval.node->u.integer = '\b';
79 yylval.node->u.integer = '\r';
83 yylval.node->u.integer = '\f';
87 yylval.node->u.integer = '\a';
91 yylval.node->u.integer = yytext[2];
98 \/ { yylval.node = node_alloc (nREGEXP);
99 read_regexp (yylval.node);
103 "BEGIN" { return tBEGIN; }
104 "END" { return tEND; }
105 "div" { return tDIV; }
106 "else" { return tELSE; }
107 "extends" { return tEXTENDS; }
108 "for" { return tFOR; }
110 "local" { return tLOCAL; }
111 "namerules" { return tNAMERULES; }
112 "return" { return tRETURN; }
113 "start" { return tSTART; }
114 "startrules" { return tSTARTRULES; }
115 "state" { return tSTATE; }
116 "sub" { return tSUB; }
117 "while" { return tWHILE; }
123 "&&" { return tAND; }
125 "++" { return tPLUSPLUS; }
126 "--" { return tMINUSMINUS; }
127 "+=" { return tADDASSIGN; }
128 "-=" { return tSUBASSIGN; }
129 "*=" { return tMULASSIGN; }
130 "div=" { return tDIVASSIGN; }
132 {real} { yylval.node = node_alloc (nREAL);
133 yylval.node->u.real = atof (yytext);
136 {integer} { yylval.node = node_alloc (nINTEGER);
137 yylval.node->u.integer = atoi (yytext);
140 {symbol} { yylval.node = node_alloc (nSYMBOL);
141 yylval.node->u.sym = xstrdup (yytext);
145 . { return yytext[0]; }
154 while ((c = input ()) != EOF)
167 yyerror (_("error: EOF in comment"));
173 yyerror (_("error: EOF in comment"));
184 read_string (len_return)
185 unsigned int *len_return;
204 yyerror (_("error: EOF in string constant"));
254 for (i = 0; i < 3; i++)
257 if ('0' <= ch && ch <= '7')
258 val = val * 8 + ch - '0';
272 if (bufpos >= buflen)
275 buf = (char *) xrealloc (buf, buflen);
282 buf2 = (char *) xmalloc (bufpos + 1);
283 memcpy (buf2, buf, bufpos);
287 *len_return = bufpos;
311 yyerror (_("error: EOF in regular expression"));
360 for (i = 0; i < 3; i++)
363 if ('0' <= ch && ch <= '7')
364 val = val * 8 + ch - '0';
375 /* Pass it through. */
384 if (bufpos >= buflen)
387 buf = (char *) xrealloc (buf, buflen);
394 /* Possible options. */
402 /* Case-insensitive regular expression. */
403 node->u.re.flags |= fRE_CASE_INSENSITIVE;
407 /* Unknown option => this belongs to the next token. */
414 buf2 = (char *) xmalloc (bufpos + 1);
415 memcpy (buf2, buf, bufpos);
419 node->u.re.data = buf2;
420 node->u.re.len = bufpos;