add isl_stream_next_token_on_same_line
authorSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Feb 2010 17:24:43 +0000 (18:24 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Feb 2010 17:24:43 +0000 (18:24 +0100)
isl_stream.c
isl_stream.h

index 192546e..8715b4f 100644 (file)
@@ -145,15 +145,18 @@ void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok)
        s->tokens[s->n_token++] = tok;
 }
 
-struct isl_token *isl_stream_next_token(struct isl_stream *s)
+static struct isl_token *next_token(struct isl_stream *s, int same_line)
 {
        int c;
        struct isl_token *tok = NULL;
        int line, col;
        int old_line = s->line;
 
-       if (s->n_token)
+       if (s->n_token) {
+               if (same_line && s->tokens[s->n_token - 1]->on_new_line)
+                       return NULL;
                return s->tokens[--s->n_token];
+       }
 
        s->len = 0;
 
@@ -163,16 +166,16 @@ struct isl_token *isl_stream_next_token(struct isl_stream *s)
                        while ((c = isl_stream_getc(s)) != -1 && c != '\n')
                                /* nothing */
                                ;
-                       if (c == -1)
+                       if (c == -1 || (same_line && c == '\n'))
                                break;
-               } else if (!isspace(c))
+               } else if (!isspace(c) || (same_line && c == '\n'))
                        break;
        }
 
        line = s->line;
        col = s->col;
 
-       if (c == -1)
+       if (c == -1 || (same_line && c == '\n'))
                return NULL;
        if (c == '(' ||
            c == ')' ||
@@ -308,6 +311,16 @@ error:
        return NULL;
 }
 
+struct isl_token *isl_stream_next_token(struct isl_stream *s)
+{
+       return next_token(s, 0);
+}
+
+struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s)
+{
+       return next_token(s, 1);
+}
+
 int isl_stream_eat(struct isl_stream *s, int type)
 {
        struct isl_token *tok;
index cd39b59..d83c705 100644 (file)
@@ -61,6 +61,7 @@ void isl_stream_free(struct isl_stream *s);
 void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg);
 
 struct isl_token *isl_stream_next_token(struct isl_stream *s);
+struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s);
 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
 int isl_stream_eat(struct isl_stream *s, int type);