]> git.cworth.org Git - ttt/blob - src/ttt-lex.l
06685c4a178565ed9d969a2dad82296a6ba24f4e
[ttt] / src / ttt-lex.l
1   /* Definitions */
2
3 %option reentrant
4 %option noyywrap
5
6 %{
7 #include "ttt-token.h"
8
9 #define YY_DECL int yylex (yyscan_t yyscanner, ttt_token_t *token)
10
11 #define STRING_BUF_SIZE 8000
12 %}
13
14 %x STRING
15
16 %%
17
18         char string_buf[STRING_BUF_SIZE];
19         char *string_buf_ptr;
20
21   /* Rules */
22
23 \r\n            {
24                         token->type = TTT_TOKEN_TYPE_NEWLINE;
25                         return token->type;
26                 }
27
28 \"              {
29                         string_buf_ptr = string_buf;
30                         BEGIN (STRING);
31                 }
32
33 <STRING>{
34                 \\\"            {
35                                         *string_buf_ptr++ = '"';
36                                 }
37
38                 \\              {
39                                         *string_buf_ptr++ = '\\';
40                                 }
41
42                 [^\\\"\\]+      {
43                                         char *s = yytext;
44                                         
45                                         while (*s)
46                                               *string_buf_ptr++ = *s++;
47                                 }
48
49                 \"              {
50                                         BEGIN (INITIAL);
51                                         *string_buf_ptr = '\0';
52                                         token->type = TTT_TOKEN_TYPE_STRING;
53                                         token->u.string = xstrdup (string_buf);
54                                         return token->type;
55                                 }
56 }
57
58 [^ \t\r\n\"][^ \t\r\n\"]*       {
59                         token->type = TTT_TOKEN_TYPE_STRING;
60                         token->u.string = xstrdup (yytext);
61                         return token->type;
62                 }
63
64 [ \t\r\n]       ;