#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
struct macro
{
+ struct hmap_node hmap_node; /* Indexed by 'name'. */
char *name;
struct macro_param *params;
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 */