/* Definitions */ %option reentrant %option noyywrap %{ #include "ttt-token.h" #define YY_DECL int yylex (yyscan_t yyscanner, ttt_token_t *token) #define STRING_BUF_SIZE 8000 %} %x STRING %% char string_buf[STRING_BUF_SIZE]; char *string_buf_ptr; /* Rules */ \r\n { token->type = TTT_TOKEN_TYPE_NEWLINE; return token->type; } \" { string_buf_ptr = string_buf; BEGIN (STRING); } { \\\" { *string_buf_ptr++ = '"'; } \\ { *string_buf_ptr++ = '\\'; } [^\\\"\\]+ { char *s = yytext; while (*s) *string_buf_ptr++ = *s++; } \" { BEGIN (INITIAL); *string_buf_ptr = '\0'; token->type = TTT_TOKEN_TYPE_STRING; token->u.string = xstrdup (string_buf); return token->type; } } [^ \t\r\n\"][^ \t\r\n\"]* { token->type = TTT_TOKEN_TYPE_STRING; token->u.string = xstrdup (yytext); return token->type; } [ \t\r\n] ;