[Mercury Feature request] Minimize the need for escaping variable names

Some thoughts about reserved keywords and escaping.

It this moment a long list of keywords need escaping: https://docs.microsoft.com/en-us/dotnet/visual-basic/language-reference/keywords

But - correct me when I am wrong - only the keywords that can be the first keyword of a statement have to be reserved, and only because - when used as an identifier - it would confuse the parser.

As an example:

Dim For as String

Is not problem for the parser.

For = "abc"

is a problem. because the reserved keyword For is starting a For-Next loop according to the parser.
And that’s why it should be escaped.

For variable and properties
But with VB6 syntax in mind, we can re-introduce the LET and SET keywords.
LET is the old Basic keyword to assign a value to a value type or string (already optional in VB6), SET the keyword to assign a reference type.

When we bring this back, almost no keyword has to be reserved anymore.

Dim For As String
Let For = "abc"

won’t confuse the parser

Only the words that can still confuse the parser, like ByVal, ByRef, ParamArray, Optional etc, that can be used in a parameter definition have to be reserved.

For methods
For methods, only the system method names have to be reserved, because you don’t want to allow system functions to be overridden.

For all others we have the keyword Call - that is now completely optional.


Sub For()
Call For

Could be allowed
Just as:

Sub For()

And - as now mandatory:

Sub [For]

So escaping should not be needed on the definition.
Only on the call or assignment if Call, Let or Set is not used.

The only words needed to be reserved are keywords that do actions on parameters or variables, the keywords that have meaning on their own and keywords.

So “And” is reserved, just like “Return”.
But “For” is not.