PaesslerAG/gval

Variables beginning with a number

informixter opened this issue · 2 comments

Hi, thanks for your work.

I found one annoying error in the execution process. When you define parameters that start with a number, then a parsing error occurs.

For example, this code will generate an error parsing error: 2_GH :1:2 - 1:5 unexpected Ident while scanning operator

resultEval, err := gval.Evaluate("2_GH", map[string]interface{}{
		"2_GH": 10,
	})

Can you please tell me how to fix this? Is this a bug or a feature?

Hi,

you are welcome. Yes variable names can not begin with a number but you can acccess these variables via the JSONPath extension:

resultEval, err := gval.Evaluate(`$["2_GH"]`, map[string]interface{}{
		"2_GH": 10,
	}, jsonpath.Language())

There is an example in the godoc.

Does this solve your problem?

Thanks for the answer.
It does not solve this issue, but the ticket can be closed.
At this stage, we decided to add the prefix "VAR_" to the variable.

resultEval, err := gval.Evaluate("VAR_2_GH", map[string]interface{}{
		"VAR_2_GH": 10,
	})