Update to commit e2647ad952b4d7afc9a186429c181efbc4958786
[inform.git] / src / syntax.c
index 0896af9b3427441e3972eafe91f9ebe947ea4da4..08e61c90da922db2ccc7dc159f2026419d8683bc 100644 (file)
@@ -1,9 +1,8 @@
 /* ------------------------------------------------------------------------- */
 /*   "syntax" : Syntax analyser and compiler                                 */
 /*                                                                           */
-/* Copyright (c) Graham Nelson 1993 - 2020                                   */
-/*                                                                           */
-/* This file is part of Inform.                                              */
+/*   Part of Inform 6.35                                                     */
+/*   copyright (c) Graham Nelson 1993 - 2020                                 */
 /*                                                                           */
 /* Inform is free software: you can redistribute it and/or modify            */
 /* it under the terms of the GNU General Public License as published by      */
@@ -16,7 +15,7 @@
 /* GNU General Public License for more details.                              */
 /*                                                                           */
 /* You should have received a copy of the GNU General Public License         */
-/* along with Inform. If not, see https://gnu.org/licenses/                  */
+/* along with Inform. If not, see https://gnu.org/licenses/                  *
 /*                                                                           */
 /* ------------------------------------------------------------------------- */
 
@@ -85,13 +84,7 @@ extern void get_next_token_with_directives(void)
 
        This is called while parsing a long construct, such as Class or
        Object, where we want to support internal #ifdefs. (Although
-       function-parsing predates this and doesn't make use of it.)
-
-       (Technically this permits *any* #-directive, which means you
-       can define global variables or properties or what-have-you in
-       the middle of an object. You can do that in the middle of an
-       object, too. Don't. It's about as well-supported as Wile E.
-       Coyote one beat before the plummet-lines kick in.) */
+       function-parsing predates this and doesn't make use of it.) */
 
     int directives_save, segment_markers_save, statements_save;
 
@@ -157,6 +150,8 @@ extern int parse_directive(int internal_flag)
         TRUE if encountered with a # prefix inside a routine or object
         definition.
 
+        (Only directives like #ifdef are permitted inside a definition.)
+
         Returns: TRUE if program continues, FALSE if end of file reached.    */
 
     int routine_symbol, rep_symbol;
@@ -185,12 +180,15 @@ extern int parse_directive(int internal_flag)
         df_dont_note_global_symbols = TRUE;
         get_next_token();
         df_dont_note_global_symbols = FALSE;
-        if ((token_type != SYMBOL_TT)
-            || ((!(sflags[token_value] & UNKNOWN_SFLAG))
-                && (!(sflags[token_value] & REPLACE_SFLAG))))
+        if (token_type != SYMBOL_TT)
         {   ebf_error("routine name", token_text);
             return(FALSE);
         }
+        if ((!(sflags[token_value] & UNKNOWN_SFLAG))
+            && (!(sflags[token_value] & REPLACE_SFLAG)))
+        {   ebf_symbol_error("routine name", token_text, typename(stypes[token_value]), slines[token_value]);
+            return(FALSE);
+        }
 
         routine_symbol = token_value;
 
@@ -614,6 +612,11 @@ extern void parse_code_block(int break_label, int continue_label,
     {   do
         {   begin_syntax_line(TRUE);
             get_next_token();
+            
+            if ((token_type == SEP_TT) && (token_value == HASH_SEP))
+            {   parse_directive(TRUE);
+                continue;
+            }
             if (token_type == SEP_TT && token_value == CLOSE_BRACE_SEP)
             {   if (switch_clause_made && (!default_clause_made))
                     assemble_label_no(switch_label);