DavidKinder / Inform6

The latest version of the Inform 6 compiler, used for generating interactive fiction games.
http://inform-fiction.org/
Other
199 stars 32 forks source link

Reject quoted local variables #210

Closed erkyrath closed 1 year ago

erkyrath commented 1 year ago

Some ancient version of Inform imagined it was a good idea to quote your local variables:

[ MyTest "x";
  return x+1;
];

You can use this to define local variables which are not symbols, which is entirely useless as far as I can tell -- you can't use them in expressions or statements.

[ MyTest "!" "x+1";
  return x+1;   ! error because there is no variable "x"
];

I would like to get rid of this pointless feature. In theory this might break some previously-valid code, like the first example above, but I bet it doesn't.

erkyrath commented 1 year ago

This should just be a matter of removing the if (token_type != DQ_TT) test in parse_routine().

erkyrath commented 1 year ago

Update: aaaaaaaaaagggghhhhhh.

Ignoring quotes is a general behavior of get_next_token() when dont_enter_into_symbol_table is true. Which means that this inconsistency turns up in lots of places! All of the following compile without error:

Switches v5;
Switches "v5";

Verb 'foo' * -> "Acting";

[ TestMe foo "bar";
    <"Acting">;
];

I think that's everywhere we parse a symbol with dont_enter_into_symbol_table set. (There's places where we use it but don't parse symbols, e.g., code that is #if'd out.)

It should be okay to reject quoted symbols in all of these cases. Except maybe the Strings directive? But that's explicitly deprecated now, with a warning.

Conclusion: I am going to remove this general behavior -- get_next_token() should distinguish between quoted strings and bare-strings. All the above cases will only accept bare-strings.