From: Ben Pfaff Date: Mon, 28 Jun 2021 06:09:00 +0000 (-0700) Subject: fix up macro expansion X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=458ce22a11c42436ad318d76bcbb39ed855d1c27;p=pspp fix up macro expansion --- diff --git a/src/language/lexer/lexer.c b/src/language/lexer/lexer.c index e8a2677986..6e9bba43a7 100644 --- a/src/language/lexer/lexer.c +++ b/src/language/lexer/lexer.c @@ -1842,7 +1842,9 @@ lex_source_get (const struct lex_source *src_) .representation = ss_buffer (&src->buffer[start - src->tail], end - start), }; + src->middle += middle_ofs + 1; n_call = macro_expander_add (me, &mt); + src->middle -= middle_ofs + 1; } if (n_call < 0) { @@ -1863,7 +1865,7 @@ lex_source_get (const struct lex_source *src_) const struct lex_token *call_first = &src->tokens[src->middle & (src->capacity - 1)]; const struct lex_token *call_last - = &src->tokens[(src->middle + n_call) & (src->capacity - 1)]; + = &src->tokens[(src->middle + n_call - 1) & (src->capacity - 1)]; size_t call_pos = call_first->token_pos; size_t call_len = (call_last->token_pos + call_last->token_len) - call_pos; size_t line_pos = call_first->line_pos; diff --git a/src/language/lexer/macro.c b/src/language/lexer/macro.c index bee23c999c..786aeea54a 100644 --- a/src/language/lexer/macro.c +++ b/src/language/lexer/macro.c @@ -1525,7 +1525,7 @@ macro_parse_let (const struct macro_token *tokens, size_t n_tokens, if (is_macro_keyword (var_name) || macro_find_parameter_by_name (me->macro, var_name)) { - printf ("cannot use argument name or macro keyword as !LET variable\n"); + printf ("cannot use argument name or macro keyword %.*s as !LET variable\n", (int) var_name.length, var_name.string); return 0; } p++; @@ -1591,7 +1591,7 @@ macro_expand_do (const struct macro_token *tokens, size_t n_tokens, if (is_macro_keyword (var_name) || macro_find_parameter_by_name (me->macro, var_name)) { - printf ("cannot use argument name or macro keyword as !DO variable\n"); + printf ("cannot use argument name or macro keyword %.*s as !DO variable\n", (int) var_name.length, var_name.string); return 0; } p++; diff --git a/tests/language/control/define.at b/tests/language/control/define.at index adfd18c884..930b9ddf4c 100644 --- a/tests/language/control/define.at +++ b/tests/language/control/define.at @@ -853,8 +853,8 @@ DEBUG EXPAND. !for2 x=1 y=5. ]) AT_CHECK([pspp --testing-mode define.sps], [0], [dnl -cannot use argument name or macro keyword as !DO variable -cannot use argument name or macro keyword as !DO variable +cannot use argument name or macro keyword !x as !DO variable +cannot use argument name or macro keyword !noexpand as !DO variable !DO 1 = 1 !TO 5 !var !DOEND. !DO !noexpand = 1 !TO 5 !var !DOEND. @@ -1061,14 +1061,14 @@ DEFINE !macro2() !ENDDEFINE. DEBUG EXPAND. -!macro 1. +!macro x=1. !macro2. ]) AT_CHECK([pspp --testing-mode define.sps -O format=csv], [0], [dnl -cannot use argument name or macro keyword as !LET variable -cannot use argument name or macro keyword as !LET variable +cannot use argument name or macro keyword !x as !LET variable +cannot use argument name or macro keyword !do as !LET variable expected macro variable name following !DO -!LET = +!LET 1 = 1 !LET !do = x ])