Break macro structure definition into new file.
[pspp] / src / language / lexer / macro.h
1 /* PSPP - a program for statistical analysis.
2    Copyright (C) 2021 Free Software Foundation, Inc.
3
4    This program is free software: you can redistribute it and/or modify
5    it under the terms of the GNU General Public License as published by
6    the Free Software Foundation, either version 3 of the License, or
7    (at your option) any later version.
8
9    This program is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12    GNU General Public License for more details.
13
14    You should have received a copy of the GNU General Public License
15    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17 #ifndef MACRO_H
18 #define MACRO_H 1
19
20 #include <stdbool.h>
21 #include <stddef.h>
22
23 #include "language/lexer/token.h"
24
25 struct macro_tokens
26   {
27     struct token *tokens;
28     size_t n;
29   };
30
31 void macro_tokens_uninit (struct macro_tokens *);
32
33 struct macro_param
34   {
35     char *name;                 /* NULL for a positional parameter. */
36     struct macro_tokens def;    /* Default expansion. */
37     bool expand_arg;            /* Macro-expand the argument? */
38
39     enum
40       {
41         ARG_N_TOKENS,
42         ARG_CHAREND,
43         ARG_ENCLOSE,
44         ARG_CMDEND
45       }
46     arg_type;
47     union
48       {
49         int n_tokens;
50         struct token charend;
51         struct token enclose[2];
52       };
53   };
54
55 struct macro
56   {
57     char *name;
58
59     struct macro_param *params;
60     size_t n_params;
61
62     char **body;
63     size_t n_body;
64   };
65
66 void macro_destroy (struct macro *);
67
68 #endif /* macro.h */