isl_stream: add some auxiliary functions
authorSven Verdoolaege <skimo@kotnet.org>
Tue, 23 Feb 2010 14:28:15 +0000 (15:28 +0100)
committerSven Verdoolaege <skimo@kotnet.org>
Thu, 4 Mar 2010 18:04:56 +0000 (19:04 +0100)
isl_stream.c
isl_stream.h

index 650b115..64f81ee 100644 (file)
@@ -342,6 +342,50 @@ struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s)
        return next_token(s, 1);
 }
 
+int isl_stream_eat_if_available(struct isl_stream *s, int type)
+{
+       struct isl_token *tok;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               return 0;
+       if (tok->type == type) {
+               isl_token_free(tok);
+               return 1;
+       }
+       isl_stream_push_token(s, tok);
+       return 0;
+}
+
+int isl_stream_next_token_is(struct isl_stream *s, int type)
+{
+       struct isl_token *tok;
+       int r;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               return 0;
+       r = tok->type == type;
+       isl_stream_push_token(s, tok);
+       return r;
+}
+
+char *isl_stream_read_ident_if_available(struct isl_stream *s)
+{
+       struct isl_token *tok;
+
+       tok = isl_stream_next_token(s);
+       if (!tok)
+               return NULL;
+       if (tok->type == ISL_TOKEN_IDENT) {
+               char *ident = strdup(tok->u.s);
+               isl_token_free(tok);
+               return ident;
+       }
+       isl_stream_push_token(s, tok);
+       return NULL;
+}
+
 int isl_stream_eat(struct isl_stream *s, int type)
 {
        struct isl_token *tok;
@@ -358,6 +402,19 @@ int isl_stream_eat(struct isl_stream *s, int type)
        return -1;
 }
 
+int isl_stream_is_empty(struct isl_stream *s)
+{
+       struct isl_token *tok;
+
+       tok = isl_stream_next_token(s);
+
+       if (!tok)
+               return 1;
+
+       isl_stream_push_token(s, tok);
+       return 0;
+}
+
 void isl_stream_free(struct isl_stream *s)
 {
        if (!s)
index f0c2fe1..905476b 100644 (file)
@@ -63,8 +63,12 @@ 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);
+int isl_stream_next_token_is(struct isl_stream *s, int type);
 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
+int isl_stream_eat_if_available(struct isl_stream *s, int type);
+char *isl_stream_read_ident_if_available(struct isl_stream *s);
 int isl_stream_eat(struct isl_stream *s, int type);
+int isl_stream_is_empty(struct isl_stream *s);
 
 #if defined(__cplusplus)
 }