#ifndef TOKEN_H
#define TOKEN_H 1
+#include <stdbool.h>
#include <stdio.h>
+#include "libpspp/assertion.h"
#include "libpspp/str.h"
#include "data/identifier.h"
struct substring string;
};
-#define TOKEN_INITIALIZER(TYPE, NUMBER, STRING) \
- { TYPE, NUMBER, SS_LITERAL_INITIALIZER (STRING) }
+void token_copy (struct token *, const struct token *);
+void token_uninit (struct token *);
-void token_init (struct token *);
-void token_destroy (struct token *);
+bool token_equal (const struct token *, const struct token *);
char *token_to_string (const struct token *);
void token_print (const struct token *, FILE *);
+static inline bool token_is_number (const struct token *);
+static inline double token_number (const struct token *);
+bool token_is_integer (const struct token *);
+long token_integer (const struct token *);
+static inline bool token_is_string (const struct token *);
+
+static inline bool
+token_is_number (const struct token *t)
+{
+ return t->type == T_POS_NUM || t->type == T_NEG_NUM;
+}
+
+static inline double
+token_number (const struct token *t)
+{
+ assert (token_is_number (t));
+ return t->number;
+}
+
+static inline bool
+token_is_string (const struct token *t)
+{
+ return t->type == T_STRING;
+}
+\f
+struct tokens
+ {
+ struct token *tokens;
+ size_t n;
+ size_t allocated;
+ };
+
+void tokens_copy (struct tokens *, const struct tokens *);
+void tokens_uninit (struct tokens *);
+void tokens_add (struct tokens *, const struct token *);
+
+void tokens_print (const struct tokens *, FILE *);
+
#endif /* token.h */