projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Some variables are ordinal.
[pspp]
/
src
/
language
/
lexer
/
macro.c
diff --git
a/src/language/lexer/macro.c
b/src/language/lexer/macro.c
index 977436a6041b32a7dc39f31d57daebc7262ceb9b..e5805f035670b33e7b6f62aea55b58a623818ad4 100644
(file)
--- a/
src/language/lexer/macro.c
+++ b/
src/language/lexer/macro.c
@@
-334,6
+334,8
@@
classify_token (enum token_type type)
case T_RPAREN:
case T_LBRACK:
case T_RBRACK:
case T_RPAREN:
case T_LBRACK:
case T_RBRACK:
+ case T_LCURLY:
+ case T_RCURLY:
return TC_PUNCT;
case T_PLUS:
return TC_PUNCT;
case T_PLUS:
@@
-341,6
+343,7
@@
classify_token (enum token_type type)
case T_ASTERISK:
case T_SLASH:
case T_EQUALS:
case T_ASTERISK:
case T_SLASH:
case T_EQUALS:
+ case T_COLON:
case T_AND:
case T_OR:
case T_NOT:
case T_AND:
case T_OR:
case T_NOT:
@@
-359,6
+362,7
@@
classify_token (enum token_type type)
return TC_BINOP;
case T_COMMA:
return TC_BINOP;
case T_COMMA:
+ case T_SEMICOLON:
return TC_COMMA;
}
return TC_COMMA;
}
@@
-707,7
+711,8
@@
mc_enclose (struct macro_call *mc, const struct macro_token *mt,
mc->n_tokens++;
struct macro_tokens **argp = &mc->args[p - mc->macro->params];
mc->n_tokens++;
struct macro_tokens **argp = &mc->args[p - mc->macro->params];
- *argp = xzalloc (sizeof **argp);
+ if (!*argp)
+ *argp = xzalloc (sizeof **argp);
mc->state = MC_ARG;
return 0;
}
mc->state = MC_ARG;
return 0;
}
@@
-986,12
+991,7
@@
parse_function_args (const struct macro_expander *me,
const char *function,
struct string_array *args)
{
const char *function,
struct string_array *args)
{
- if (n < 2 || mts[1].token.type != T_LPAREN)
- {
- macro_error (me->stack, n > 1 ? &mts[1] : NULL,
- _("`(' expected following %s."), function);
- return 0;
- }
+ assert (n >= 2 && mts[1].token.type == T_LPAREN);
for (size_t i = 2; i < n; )
{
for (size_t i = 2; i < n; )
{
@@
-1043,7
+1043,8
@@
unquote_string (const char *s, enum segmenter_mode segmenter_mode,
return false;
}
return false;
}
- ds_put_substring (content, token1.string);
+ if (content)
+ ds_put_substring (content, token1.string);
token_uninit (&token1);
return true;
}
token_uninit (&token1);
return true;
}
@@
-1090,7
+1091,6
@@
expand_macro_function (const struct macro_expander *me,
MF_HEAD,
MF_INDEX,
MF_LENGTH,
MF_HEAD,
MF_INDEX,
MF_LENGTH,
- MF_NULL,
MF_QUOTE,
MF_SUBSTR,
MF_TAIL,
MF_QUOTE,
MF_SUBSTR,
MF_TAIL,
@@
-1104,7
+1104,6
@@
expand_macro_function (const struct macro_expander *me,
[MF_HEAD] = { "!HEAD", 1, 1 },
[MF_INDEX] = { "!INDEX", 2, 2 },
[MF_LENGTH] = { "!LENGTH", 1, 1 },
[MF_HEAD] = { "!HEAD", 1, 1 },
[MF_INDEX] = { "!INDEX", 2, 2 },
[MF_LENGTH] = { "!LENGTH", 1, 1 },
- [MF_NULL] = { "!NULL", 0, 0 },
[MF_QUOTE] = { "!QUOTE", 1, 1 },
[MF_SUBSTR] = { "!SUBSTR", 2, 3 },
[MF_TAIL] = { "!TAIL", 1, 1 },
[MF_QUOTE] = { "!QUOTE", 1, 1 },
[MF_SUBSTR] = { "!SUBSTR", 2, 3 },
[MF_TAIL] = { "!TAIL", 1, 1 },
@@
-1112,7
+1111,16
@@
expand_macro_function (const struct macro_expander *me,
[MF_UPCASE] = { "!UPCASE", 1, 1 },
};
[MF_UPCASE] = { "!UPCASE", 1, 1 },
};
- /* Is this a macro function? */
+ if (lex_id_match_n (ss_cstr ("!NULL"), input[0].token.string, 4))
+ return 1;
+
+ if (n_input < 2 || input[1].token.type != T_LPAREN)
+ {
+ /* Only consider macro functions when the name is followed by '('. */
+ return 0;
+ }
+
+ /* Is this a macro function name? */
const struct macro_function *mf;
for (mf = mfs; ; mf++)
{
const struct macro_function *mf;
for (mf = mfs; ; mf++)
{
@@
-1127,13
+1135,14
@@
expand_macro_function (const struct macro_expander *me,
}
enum macro_function_id id = mf - mfs;
}
enum macro_function_id id = mf - mfs;
- if (id == MF_NULL)
- return 1;
struct string_array args = STRING_ARRAY_INITIALIZER;
size_t n_consumed = parse_function_args (me, input, n_input, mf->name, &args);
if (!n_consumed)
struct string_array args = STRING_ARRAY_INITIALIZER;
size_t n_consumed = parse_function_args (me, input, n_input, mf->name, &args);
if (!n_consumed)
- return 0;
+ {
+ string_array_destroy (&args);
+ return 0;
+ }
if (args.n < mf->min_args || args.n > mf->max_args)
{
if (args.n < mf->min_args || args.n > mf->max_args)
{
@@
-1156,6
+1165,7
@@
expand_macro_function (const struct macro_expander *me,
mf->name);
else
NOT_REACHED ();
mf->name);
else
NOT_REACHED ();
+ string_array_destroy (&args);
return 0;
}
return 0;
}
@@
-1834,6
+1844,7
@@
macro_expand_do (const struct macro_token *tokens, size_t n_tokens,
macro_expand (p, do_end - p, &subme, exp);
}
macro_expand (p, do_end - p, &subme, exp);
}
+ macro_tokens_uninit (&items);
return do_end - tokens + 1;
}
else if (p < end && p->token.type == T_EQUALS)
return do_end - tokens + 1;
}
else if (p < end && p->token.type == T_EQUALS)