scan: Get rid of scan token types in favor of new scan result state.
[pspp] / src / language / lexer / macro.c
index 6b5d62430195b745a7e29e19eca99b3ef4e206ef..b5cbf2dfc6cc0bb4142fa163a2ecbd522a560204 100644 (file)
@@ -248,6 +248,7 @@ macro_tokens_from_string__ (struct macro_tokens *mts, const struct substring src
       struct scanner scanner;
       scanner_init (&scanner, token);
 
+      enum scan_result result;
       for (;;)
         {
           enum segment_type type;
@@ -258,37 +259,40 @@ macro_tokens_from_string__ (struct macro_tokens *mts, const struct substring src
           struct substring segment = ss_head (state.body, seg_len);
           ss_advance (&state.body, seg_len);
 
-          enum scan_result result = scanner_push (&scanner, type, segment, token);
+          result = scanner_push (&scanner, type, segment, token);
           if (result == SCAN_SAVE)
             saved = state;
-          else if (result == SCAN_BACK)
-            {
-              state = saved;
-              break;
-            }
-          else if (result == SCAN_DONE)
+          else if (result != SCAN_MORE)
             break;
         }
 
-      /* We have a token in 'token'. */
-      mt.syntax.length = state.body.string - mt.syntax.string;
-      if (is_scan_type (token->type))
+
+      switch (result)
         {
-          if (token->type != SCAN_SKIP)
-            {
-              char *s = scan_token_to_error (token);
-              if (stack)
-                {
-                  mt.token.type = T_STRING;
-                  macro_error (stack, &mt, "%s", s);
-                }
-              else
-                msg (SE, "%s", s);
-              free (s);
-            }
+        case SCAN_BACK:
+          state = saved;
+          /* Fall through. */
+        case SCAN_DONE:
+          mt.syntax.length = state.body.string - mt.syntax.string;
+          macro_tokens_add (mts, &mt);
+          break;
+
+        case SCAN_EMPTY:
+          break;
+
+        case SCAN_ERROR:
+          mt.syntax.length = state.body.string - mt.syntax.string;
+          if (stack)
+            macro_error (stack, &mt, "%s", token->string.string);
+          else
+            msg (SE, "%s", token->string.string);
+          break;
+
+        case SCAN_MORE:
+        case SCAN_SAVE:
+          NOT_REACHED ();
         }
-      else
-        macro_tokens_add (mts, &mt);
+
       token_uninit (token);
     }
 }
@@ -1016,17 +1020,15 @@ unquote_string (const char *s, enum segmenter_mode segmenter_mode,
   string_lexer_init (&slex, s, strlen (s), segmenter_mode, true);
 
   struct token token1;
-  if (!string_lexer_next (&slex, &token1))
-    return false;
-
-  if (token1.type != T_STRING)
+  if (string_lexer_next (&slex, &token1) != SLR_TOKEN
+      || token1.type != T_STRING)
     {
       token_uninit (&token1);
       return false;
     }
 
   struct token token2;
-  if (string_lexer_next (&slex, &token2))
+  if (string_lexer_next (&slex, &token2) != SLR_END)
     {
       token_uninit (&token1);
       token_uninit (&token2);