Break macro structure definition into new file.
[pspp] / src / language / lexer / macro.h
diff --git a/src/language/lexer/macro.h b/src/language/lexer/macro.h
new file mode 100644 (file)
index 0000000..2264ad6
--- /dev/null
@@ -0,0 +1,68 @@
+/* PSPP - a program for statistical analysis.
+   Copyright (C) 2021 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation, either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef MACRO_H
+#define MACRO_H 1
+
+#include <stdbool.h>
+#include <stddef.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. */
+    bool expand_arg;            /* Macro-expand the argument? */
+
+    enum
+      {
+        ARG_N_TOKENS,
+        ARG_CHAREND,
+        ARG_ENCLOSE,
+        ARG_CMDEND
+      }
+    arg_type;
+    union
+      {
+        int n_tokens;
+        struct token charend;
+        struct token enclose[2];
+      };
+  };
+
+struct macro
+  {
+    char *name;
+
+    struct macro_param *params;
+    size_t n_params;
+
+    char **body;
+    size_t n_body;
+  };
+
+void macro_destroy (struct macro *);
+
+#endif /* macro.h */