]> git.cworth.org Git - ttt/blobdiff - src/ttt-lex.l
2005-12-01 Richard D. Worth <richard@theworths.org>
[ttt] / src / ttt-lex.l
index 2a9d8e247908e33e5754a850492d9f52c3243ded..06685c4a178565ed9d969a2dad82296a6ba24f4e 100644 (file)
@@ -5,12 +5,60 @@
 
 %{
 #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                   return TTT_TOKEN_NEWLINE;
-[^ \t\r\n][^ \t\r\n]*  return TTT_TOKEN_STRING;
-[ \t\r\n]              ;
+\r\n           {
+                       token->type = TTT_TOKEN_TYPE_NEWLINE;
+                       return token->type;
+               }
+
+\"             {
+                       string_buf_ptr = string_buf;
+                       BEGIN (STRING);
+               }
+
+<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]      ;