From 6068227c04afae66dfa349505c3ef5b955bdb07e Mon Sep 17 00:00:00 2001 From: Sven Verdoolaege Date: Thu, 22 Apr 2010 07:50:49 +0200 Subject: [PATCH] isl_stream: accept string tokens --- include/isl_stream.h | 1 + isl_stream.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/include/isl_stream.h b/include/isl_stream.h index 2480e2f..b3a91f9 100644 --- a/include/isl_stream.h +++ b/include/isl_stream.h @@ -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 { diff --git a/isl_stream.c b/isl_stream.c index f85d90f..f88ec07 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -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); -- 2.7.4