#include "language/command.h"
#include "language/lexer/lexer.h"
+#include "language/lexer/macro.h"
#include "language/lexer/scan.h"
#include "language/lexer/token.h"
return false;
}
-struct tokens
- {
- struct token *tokens;
- size_t n;
- };
-
-struct macro_param
- {
- char *name; /* NULL for a positional parameter. */
- struct 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;
- };
-
-static void macro_destroy (struct macro *);
-
static bool
parse_quoted_token (struct lexer *lexer, struct token *token)
{
macro_destroy (m);
return CMD_FAILURE;
}
-
-static void
-tokens_uninit (struct tokens *tokens)
-{
- for (size_t i = 0; i < tokens->n; i++)
- token_destroy (&tokens->tokens[i]);
- free (tokens->tokens);
-}
-
-static void
-macro_destroy (struct macro *m)
-{
- if (!m)
- return;
-
- free (m->name);
- for (size_t i = 0; i < m->n_params; i++)
- {
- struct macro_param *p = &m->params[i];
- free (p->name);
-
- tokens_uninit (&p->def);
-
- switch (p->arg_type)
- {
- case ARG_N_TOKENS:
- break;
-
- case ARG_CHAREND:
- token_destroy (&p->charend);
- break;
-
- case ARG_ENCLOSE:
- token_destroy (&p->enclose[0]);
- token_destroy (&p->enclose[1]);
- break;
-
- case ARG_CMDEND:
- break;
- }
- }
- free (m->params);
- for (size_t i = 0; i < m->n_body; i++)
- free (m->body[i]);
- free (m->body);
- free (m);
-}
-
src/language/lexer/include-path.h \
src/language/lexer/lexer.c \
src/language/lexer/lexer.h \
+ src/language/lexer/macro.c \
+ src/language/lexer/macro.h \
src/language/lexer/format-parser.c \
src/language/lexer/format-parser.h \
src/language/lexer/scan.c \
--- /dev/null
+/* 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/>. */
+
+#include <config.h>
+
+#include "language/lexer/macro.h"
+
+#include <stdlib.h>
+
+void
+macro_tokens_uninit (struct macro_tokens *tokens)
+{
+ for (size_t i = 0; i < tokens->n; i++)
+ token_destroy (&tokens->tokens[i]);
+ free (tokens->tokens);
+}
+
+void
+macro_destroy (struct macro *m)
+{
+ if (!m)
+ return;
+
+ free (m->name);
+ for (size_t i = 0; i < m->n_params; i++)
+ {
+ struct macro_param *p = &m->params[i];
+ free (p->name);
+
+ macro_tokens_uninit (&p->def);
+
+ switch (p->arg_type)
+ {
+ case ARG_N_TOKENS:
+ break;
+
+ case ARG_CHAREND:
+ token_destroy (&p->charend);
+ break;
+
+ case ARG_ENCLOSE:
+ token_destroy (&p->enclose[0]);
+ token_destroy (&p->enclose[1]);
+ break;
+
+ case ARG_CMDEND:
+ break;
+ }
+ }
+ free (m->params);
+ for (size_t i = 0; i < m->n_body; i++)
+ free (m->body[i]);
+ free (m->body);
+ free (m);
+}
--- /dev/null
+/* 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 */