isl_stream: treat "-" as operator rather than as -1
[platform/upstream/isl.git] / isl_stream.c
index d22d3fa..192546e 100644 (file)
@@ -204,6 +204,13 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                }
                if (c != -1)
                        isl_stream_ungetc(s, c);
+               if (!isdigit(c)) {
+                       tok = isl_token_new(s->ctx, line, col, old_line != line);
+                       if (!tok)
+                               return NULL;
+                       tok->type = (enum isl_token_type) '-';
+                       return tok;
+               }
        }
        if (c == '-' || isdigit(c)) {
                tok = isl_token_new(s->ctx, line, col, old_line != line);
@@ -218,12 +225,8 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                                goto error;
                if (c != -1)
                        isl_stream_ungetc(s, c);
-               if (s->len == 1 && s->buffer[0] == '-')
-                       isl_int_set_si(tok->u.v, -1);
-               else {
-                       isl_stream_push_char(s, '\0');
-                       isl_int_read(tok->u.v, s->buffer);
-               }
+               isl_stream_push_char(s, '\0');
+               isl_int_read(tok->u.v, s->buffer);
                return tok;
        }
        if (isalpha(c)) {
@@ -238,6 +241,10 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                isl_stream_push_char(s, '\0');
                if (!strcasecmp(s->buffer, "exists"))
                        tok->type = ISL_TOKEN_EXISTS;
+               else if (!strcasecmp(s->buffer, "and"))
+                       tok->type = ISL_TOKEN_AND;
+               else if (!strcasecmp(s->buffer, "or"))
+                       tok->type = ISL_TOKEN_OR;
                else {
                        tok->type = ISL_TOKEN_IDENT;
                        tok->u.s = strdup(s->buffer);
@@ -246,27 +253,31 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
        }
        if (c == '>') {
                int c;
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
                if ((c = isl_stream_getc(s)) == '=') {
-                       tok = isl_token_new(s->ctx, line, col, old_line != line);
-                       if (!tok)
-                               return NULL;
                        tok->type = ISL_TOKEN_GE;
                        return tok;
                }
                if (c != -1)
                        isl_stream_ungetc(s, c);
+               tok->type = ISL_TOKEN_GT;
+               return tok;
        }
        if (c == '<') {
                int c;
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
                if ((c = isl_stream_getc(s)) == '=') {
-                       tok = isl_token_new(s->ctx, line, col, old_line != line);
-                       if (!tok)
-                               return NULL;
                        tok->type = ISL_TOKEN_LE;
                        return tok;
                }
                if (c != -1)
                        isl_stream_ungetc(s, c);
+               tok->type = ISL_TOKEN_LT;
+               return tok;
        }
        if (c == '&') {
                tok = isl_token_new(s->ctx, line, col, old_line != line);
@@ -277,6 +288,15 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                        isl_stream_ungetc(s, c);
                return tok;
        }
+       if (c == '|') {
+               tok = isl_token_new(s->ctx, line, col, old_line != line);
+               if (!tok)
+                       return NULL;
+               tok->type = ISL_TOKEN_OR;
+               if ((c = isl_stream_getc(s)) != '|' && c != -1)
+                       isl_stream_ungetc(s, c);
+               return tok;
+       }
 
        tok = isl_token_new(s->ctx, line, col, old_line != line);
        if (!tok)