work on macro calls
[pspp] / src / language / lexer / macro.h
index 2264ad628bced23a4887b4206a80b24ac01f8820..ddd65c8862409e24f928580243a16c4c1819925d 100644 (file)
 #include <stdbool.h>
 #include <stddef.h>
 
+#include "libpspp/hmap.h"
+#include "libpspp/str.h"
 #include "language/lexer/token.h"
 
-struct macro_tokens
-  {
-    struct token *tokens;
-    size_t n;
-  };
-
-void macro_tokens_uninit (struct macro_tokens *);
-
 struct macro_param
   {
     char *name;                 /* NULL for a positional parameter. */
-    struct macro_tokens def;    /* Default expansion. */
+    struct tokens def;          /* Default expansion. */
     bool expand_arg;            /* Macro-expand the argument? */
 
     enum
@@ -54,6 +48,7 @@ struct macro_param
 
 struct macro
   {
+    struct hmap_node hmap_node; /* Indexed by 'name'. */
     char *name;
 
     struct macro_param *params;
@@ -65,4 +60,27 @@ struct macro
 
 void macro_destroy (struct macro *);
 
+struct macro_set
+  {
+    struct hmap macros;
+  };
+
+const struct macro *macro_set_find (const struct macro_set *,
+                                    const char *);
+
+struct macro_expander *macro_expander_create (const struct macro_set *);
+void macro_expander_destroy (struct macro_expander *);
+
+/* Add one token to the input to macro-expand.  Returns:
+
+   -1: Advance one token without change.
+    0: Needs more tokens.
+   >0: Expand the given number of tokens.
+*/
+int macro_expander_add (struct macro_expander *, const struct token *);
+int macro_expander_add_eof (struct macro_expander *);
+
+void macro_expander_get_expansion (struct macro_expander *,
+                                   struct token **tokens, size_t *n);
+
 #endif /* macro.h */