Allow special characters in Variable names

Oct 2, 2013 at 11:31 PM
My question is quite simple, but I don't know if it could be easy to modify in source code.
I tried, but I prefer to ask first...

Is it possible be able to have some special characters to variables?
Currently, I think it is limited to a-z, A-Z, 0-9 and "_".
-> I would like to add several prefix, like $, @, or %. What should I modify in the source code to be able to do that?

Actually, I would like to do this in order to be able to cast the type of variable.
I cannot know the type within the event "ruleContext.Variables.ResolveVariableType".

I would like to add these prefix to be able to make something like this:
  • no prefix: double
  • $xxx : double[]
  • @xxx : etc.
I think it could be in the files: RegExp.vb, or CharacterElement.vb, but I'm afraid to make a change that could break everything...

Thanks a lot if you have an idea. :)
Best regards!
Oct 2, 2013 at 11:33 PM
Just to be more precise, the second part works.
Currently I use the "_" character as a prefix, but I would like to use more...

Here is my ResolveVariableType event:

static void Variables_ResolveVariableType(object sender, ResolveVariableTypeEventArgs e)

        if (e.VariableName.Substring(0, 1) == "_")
           e.VariableType = typeof(double[]);
            e.VariableType = typeof(double);

Oct 9, 2013 at 9:33 AM

In ExpressionTokenizer.vb, try to change
pattern = New TokenPattern(CInt(ExpressionConstants.IDENTIFIER), "IDENTIFIER", TokenPattern.PatternType.REGEXP, "[a-z_]\w*")
pattern = New TokenPattern(CInt(ExpressionConstants.IDENTIFIER), "IDENTIFIER", TokenPattern.PatternType.REGEXP, "[a-z_@$]\w*")
I don't recommand using % as a prefix since it is also used for the modulo operation.
Oct 23, 2013 at 9:34 PM
Thanks a lot
May 8, 2015 at 4:16 PM
Edited May 8, 2015 at 4:19 PM
Thank you for this.

I have used the "[" and "]" braces to define variables in my equations and so that they can contain spaces and other characters with it. I changed the Regex pattern as suggested and it seems to work fine.
pattern = New TokenPattern(CInt(ExpressionConstants.IDENTIFIER), "IDENTIFIER", TokenPattern.PatternType.REGEXP, "\[.+?\]")