Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

variable or function name start with number is causing syntax error #267

Closed
cuichenli opened this issue May 17, 2023 · 1 comment
Closed

Comments

@cuichenli
Copy link

cuichenli commented May 17, 2023

The code I tried:

(
  $0f = true;
  $0f
)

as the following screenshots:

image

However, this can correctly compile and execute on https://try.jsonata.org/

image

@wnm3
Copy link
Member

wnm3 commented May 17, 2023

Our definition of variable and function ID requires starting with a letter or underscore:

VAR_ID : '$' ID ;

ID
	: [\p{L}_] [\p{L}0-9_]*
	| BACK_QUOTE ~[`]* BACK_QUOTE;

There is a test case (token-conversion/case002.json) from jsonata.org that fails if I enable numbers for the first letter (you can experiment using "aa" as the first label and then finding $.aa, or using "a7" as the first label and then finding $.a7, but $.7a fails.

{
    "expr": "$.7a",
    "data": {"7a":33, "a7":55, "7":88},
    "bindings": {},
    "code": "S0201"
}

I don't think we plan to fix this and question whether jsonata.org should tighten their checking.

We use a different approach for parsing than jsonata.org so will have slight differences.

Please close if you agree you can use different variable names starting with a letter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants