]> git.cworth.org Git - ttt/blob - src/ttt-lex.l
Ignore ttt-lex.h
[ttt] / src / ttt-lex.l
1  /* ttt-lex.l - flex-based lexical analyzer
2  *
3  * Copyright © 2005 Carl Worth
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2, or (at your option)
8  * any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  * Author: Carl Worth <cworth@cworth.org>
20  */
21
22   /* Definitions */
23
24 %option reentrant
25 %option noyywrap
26
27 %{
28 #include "ttt-token.h"
29
30 #define YY_DECL int yylex (yyscan_t yyscanner, ttt_token_t *token)
31 #define STRING_BUF_SIZE 8000
32
33  /* Shut off some compiler warnings due to annoying flex bugs. */
34 YY_DECL;
35 int yyget_column  (yyscan_t yyscanner);
36 void yyset_column (int  column_no , yyscan_t yyscanner);
37
38 %}
39
40 %x STRING
41
42 %%
43
44         char string_buf[STRING_BUF_SIZE];
45         char *string_buf_ptr;
46
47   /* Rules */
48
49 \r\n            {
50                         token->type = TTT_TOKEN_TYPE_NEWLINE;
51                         return token->type;
52
53                         /* This dead code is just to shut off a
54                          * compiler warning due to an annoying flex
55                          * bug. */
56                         unput('?');
57                 }
58
59 \"              {
60                         string_buf_ptr = string_buf;
61                         BEGIN (STRING);
62                 }
63
64 <STRING>{
65                 \\\"            {
66                                         *string_buf_ptr++ = '"';
67                                 }
68
69                 \\              {
70                                         *string_buf_ptr++ = '\\';
71                                 }
72
73                 [^\\\"\\]+      {
74                                         char *s = yytext;
75                                         
76                                         while (*s)
77                                               *string_buf_ptr++ = *s++;
78                                 }
79
80                 \"              {
81                                         BEGIN (INITIAL);
82                                         *string_buf_ptr = '\0';
83                                         token->type = TTT_TOKEN_TYPE_STRING;
84                                         token->u.string = xstrdup (string_buf);
85                                         return token->type;
86                                 }
87 }
88
89 [^ \t\r\n\"][^ \t\r\n\"]*       {
90                         token->type = TTT_TOKEN_TYPE_STRING;
91                         token->u.string = xstrdup (yytext);
92                         return token->type;
93                 }
94
95 [ \t\r\n]       ;