X-Git-Url: https://git.cworth.org/git?p=ttt;a=blobdiff_plain;f=src%2Fttt-lex.l;h=06685c4a178565ed9d969a2dad82296a6ba24f4e;hp=2a9d8e247908e33e5754a850492d9f52c3243ded;hb=b18c78a24034922e7b9152a03683cf930d703dd0;hpb=7de44ed398081656115dce6db7d0a04c1a50bb34 diff --git a/src/ttt-lex.l b/src/ttt-lex.l index 2a9d8e2..06685c4 100644 --- a/src/ttt-lex.l +++ b/src/ttt-lex.l @@ -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_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] ;