isl_stream: allow user specified keywords
[isl.git] / isl_stream.h
blob76f81f0b16f34033284a370f15c2df738f61f530
1 /*
2 * Copyright 2008-2009 Katholieke Universiteit Leuven
4 * Use of this software is governed by the GNU LGPLv2.1 license
6 * Written by Sven Verdoolaege, K.U.Leuven, Departement
7 * Computerwetenschappen, Celestijnenlaan 200A, B-3001 Leuven, Belgium
8 */
10 #ifndef ISL_STREAM_H
11 #define ISL_STREAM_H
13 #include <stdio.h>
14 #include <isl_hash.h>
16 #if defined(__cplusplus)
17 extern "C" {
18 #endif
20 enum isl_token_type { ISL_TOKEN_ERROR = -1,
21 ISL_TOKEN_UNKNOWN = 256, ISL_TOKEN_VALUE,
22 ISL_TOKEN_IDENT, ISL_TOKEN_GE,
23 ISL_TOKEN_LE, ISL_TOKEN_GT, ISL_TOKEN_LT,
24 ISL_TOKEN_TO, ISL_TOKEN_AND,
25 ISL_TOKEN_OR, ISL_TOKEN_EXISTS,
26 ISL_TOKEN_DEF,
27 ISL_TOKEN_LAST };
29 struct isl_token {
30 enum isl_token_type type;
32 unsigned int on_new_line : 1;
33 int line;
34 int col;
36 union {
37 isl_int v;
38 char *s;
39 } u;
42 void isl_token_free(struct isl_token *tok);
44 struct isl_stream {
45 struct isl_ctx *ctx;
46 FILE *file;
47 const char *str;
48 int line;
49 int col;
50 int eof;
52 char *buffer;
53 size_t size;
54 size_t len;
55 int c;
57 struct isl_token *tokens[5];
58 int n_token;
60 struct isl_hash_table *keywords;
61 enum isl_token_type next_type;
64 struct isl_stream* isl_stream_new_file(struct isl_ctx *ctx, FILE *file);
65 struct isl_stream* isl_stream_new_str(struct isl_ctx *ctx, const char *str);
66 void isl_stream_free(struct isl_stream *s);
68 void isl_stream_error(struct isl_stream *s, struct isl_token *tok, char *msg);
70 struct isl_token *isl_stream_next_token(struct isl_stream *s);
71 struct isl_token *isl_stream_next_token_on_same_line(struct isl_stream *s);
72 int isl_stream_next_token_is(struct isl_stream *s, int type);
73 void isl_stream_push_token(struct isl_stream *s, struct isl_token *tok);
74 int isl_stream_eat_if_available(struct isl_stream *s, int type);
75 char *isl_stream_read_ident_if_available(struct isl_stream *s);
76 int isl_stream_eat(struct isl_stream *s, int type);
77 int isl_stream_is_empty(struct isl_stream *s);
79 enum isl_token_type isl_stream_register_keyword(struct isl_stream *s,
80 const char *name);
82 #if defined(__cplusplus)
84 #endif
86 #endif