tons of progress on macros
[pspp] / src / language / control / define.c
index 187eb9fcf840b1e7932d36c49cfc77f1bde1b1ae..e91505c726ee271a84891c601e8d453f183a41e7 100644 (file)
@@ -37,12 +37,12 @@ force_macro_id (struct lexer *lexer)
 }
 
 static bool
-match_macro_id (struct lexer *lexer, const char *id)
+match_macro_id (struct lexer *lexer, const char *keyword)
 {
-  if (id[0] != '!')
-    return lex_match_id (lexer, id);
+  if (keyword[0] != '!')
+    return lex_match_id (lexer, keyword);
   else if (lex_token (lexer) == T_MACRO_ID
-           && ss_equals_case (lex_tokss (lexer), ss_cstr (id)))
+           && lex_id_match_n (ss_cstr (keyword), lex_tokss (lexer), 4))
     {
       lex_get (lexer);
       return true;
@@ -59,7 +59,7 @@ parse_quoted_token (struct lexer *lexer, struct token *token)
 
   struct substring s = lex_tokss (lexer);
   struct string_lexer slex;
-  string_lexer_init (&slex, s.string, s.length, SEG_MODE_INTERACTIVE);
+  string_lexer_init (&slex, s.string, s.length, SEG_MODE_INTERACTIVE, true);
   struct token another_token = { .type = T_STOP };
   if (!string_lexer_next (&slex, token)
       || string_lexer_next (&slex, &another_token))
@@ -113,9 +113,23 @@ cmd_define (struct lexer *lexer, struct dataset *ds UNUSED)
         }
       else
         {
+          if (lex_token (lexer) == T_MACRO_ID)
+            {
+              lex_error (lexer, _("Keyword macro parameter must be named in "
+                                  "definition without \"!\" prefix."));
+              goto error;
+            }
           if (!lex_force_id (lexer))
             goto error;
 
+          if (is_macro_keyword (lex_tokss (lexer)))
+            {
+              lex_error (lexer, _("Cannot use macro keyword \"%s\" "
+                                  "as an argument name."),
+                         lex_tokcstr (lexer));
+              goto error;
+            }
+
           p->positional = false;
           p->name = xasprintf ("!%s", lex_tokcstr (lexer));
           lex_get (lexer);