From: Sven Verdoolaege Date: Tue, 23 Feb 2010 14:28:15 +0000 (+0100) Subject: isl_stream: add some auxiliary functions X-Git-Tag: isl-0.02~34 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=41c8814a66a9c4100621dbc57c4b75bbd13f1cbf;p=platform%2Fupstream%2Fisl.git isl_stream: add some auxiliary functions --- diff --git a/isl_stream.c b/isl_stream.c index 650b115..64f81ee 100644 --- a/isl_stream.c +++ b/isl_stream.c @@ -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) diff --git a/isl_stream.h b/isl_stream.h index f0c2fe1..905476b 100644 --- a/isl_stream.h +++ b/isl_stream.h @@ -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) }