isl_stream: accept string tokens
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 22 Apr 2010 05:50:49 +0000 (07:50 +0200)
committerSven Verdoolaege <skimo@kotnet.org>
Fri, 23 Apr 2010 10:02:54 +0000 (12:02 +0200)
include/isl_stream.h
isl_stream.c

index 2480e2f..b3a91f9 100644 (file)
@@ -25,6 +25,7 @@ enum isl_token_type { ISL_TOKEN_ERROR = -1,
                        ISL_TOKEN_TO, ISL_TOKEN_AND,
                        ISL_TOKEN_OR, ISL_TOKEN_EXISTS,
                        ISL_TOKEN_DEF, ISL_TOKEN_INFTY, ISL_TOKEN_NAN,
+                       ISL_TOKEN_STRING,
                        ISL_TOKEN_LAST };
 
 struct isl_token {
index f85d90f..f88ec07 100644 (file)
@@ -82,7 +82,7 @@ void isl_token_free(struct isl_token *tok)
                return;
        if (tok->type == ISL_TOKEN_VALUE)
                isl_int_clear(tok->u.v);
-       else if (tok->type == ISL_TOKEN_IDENT)
+       else if (tok->type == ISL_TOKEN_IDENT || tok->type == ISL_TOKEN_STRING)
                free(tok->u.s);
        free(tok);
 }
@@ -343,6 +343,21 @@ static struct isl_token *next_token(struct isl_stream *s, int same_line)
                        tok->u.s = strdup(s->buffer);
                return tok;
        }
+       if (c == '"') {
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               tok->type = ISL_TOKEN_STRING;
+               tok->u.s = NULL;
+               while ((c = isl_stream_getc(s)) != -1 && c != '"' && c != '\n')
+                       isl_stream_push_char(s, c);
+               if (c != '"') {
+                       isl_stream_error(s, NULL, "unterminated string");
+                       goto error;
+               }
+               tok->u.s = strdup(s->buffer);
+               return tok;
+       }
        if (c == ':') {
                int c;
                tok = isl_token_new(s->ctx, line, col, old_line != line);