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);
}
return ISL_TOKEN_IDENT;
}
+int isl_stream_skip_line(struct isl_stream *s)
+{
+ int c;
+
+ while ((c = isl_stream_getc(s)) != -1 && c != '\n')
+ /* nothing */
+ ;
+
+ return c == -1 ? -1 : 0;
+}
+
static struct isl_token *next_token(struct isl_stream *s, int same_line)
{
int c;
/* skip spaces and comment lines */
while ((c = isl_stream_getc(s)) != -1) {
if (c == '#') {
- while ((c = isl_stream_getc(s)) != -1 && c != '\n')
- /* nothing */
- ;
- if (c == -1 || (same_line && c == '\n'))
+ if (isl_stream_skip_line(s) < 0)
+ break;
+ c = '\n';
+ if (same_line)
break;
} else if (!isspace(c) || (same_line && c == '\n'))
break;
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;
+ }
+ isl_stream_push_char(s, '\0');
+ tok->u.s = strdup(s->buffer);
+ return tok;
+ }
if (c == ':') {
int c;
tok = isl_token_new(s->ctx, line, col, old_line != line);
}
if (c != -1)
isl_stream_ungetc(s, c);
- tok->type = ':';
+ tok->type = (enum isl_token_type) ':';
return tok;
}
if (c == '>') {
if ((c = isl_stream_getc(s)) == '=') {
tok->type = ISL_TOKEN_GE;
return tok;
- }
+ } else if (c == '>') {
+ if ((c = isl_stream_getc(s)) == '=') {
+ tok->type = ISL_TOKEN_LEX_GE;
+ return tok;
+ }
+ tok->type = ISL_TOKEN_LEX_GT;
+ } else
+ tok->type = ISL_TOKEN_GT;
if (c != -1)
isl_stream_ungetc(s, c);
- tok->type = ISL_TOKEN_GT;
return tok;
}
if (c == '<') {
if ((c = isl_stream_getc(s)) == '=') {
tok->type = ISL_TOKEN_LE;
return tok;
- }
+ } else if (c == '<') {
+ if ((c = isl_stream_getc(s)) == '=') {
+ tok->type = ISL_TOKEN_LEX_LE;
+ return tok;
+ }
+ tok->type = ISL_TOKEN_LEX_LT;
+ } else
+ tok->type = ISL_TOKEN_LT;
if (c != -1)
isl_stream_ungetc(s, c);
- tok->type = ISL_TOKEN_LT;
return tok;
}
if (c == '&') {
return 0;
}
+void isl_stream_flush_tokens(struct isl_stream *s)
+{
+ int i;
+
+ if (!s)
+ return;
+ for (i = 0; i < s->n_token; ++i)
+ isl_token_free(s->tokens[i]);
+ s->n_token = 0;
+}
+
void isl_stream_free(struct isl_stream *s)
{
if (!s)