lexer: Factor some token inspectors out into new token functions.
[pspp] / src / language / lexer / token.h
index b334edfef6c385cdc8a28482198dbb8ce8088a59..6decb1b66b58bdf8b3d7c59d0f88a1bcc03c1c36 100644 (file)
@@ -19,6 +19,7 @@
 
 #include <stdbool.h>
 #include <stdio.h>
+#include "libpspp/assertion.h"
 #include "libpspp/str.h"
 #include "data/identifier.h"
 
@@ -41,6 +42,31 @@ 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
   {