Maybe an issue in `identifier` definition ?
shulard opened this issue · 2 comments
Hello,
I'm currently using Hoa\Ruler in a project to validate complex form fields rules.
I use UUID v4 as field name so I can have a rule like this :
"baacf872-d554-4125-95e2-b16cdf3dd8f3 = "GIST" or 4e213f7d-7be9-45c5-bb8c-0431351bd0dd = GIST"
This rules doesn't compile properly because the second field identifier start with an integer so the analyzed token sequence is :
- identifier :
baacf872-d554-4125-95e2-b16cdf3dd8f3
- operator :
=
- string =
"GIST"
- operator :
or
- integer:
4
- indentifier :
e213f7d-7be9-45c5-bb8c-0431351bd0dd
- operator :
=
- string =
"GIST"
I don't know if it's a real issue because in programming languages a variable name shouldn't start with an integer but I still prefer create an issue to be sure 😄.
I've bypassed my problem by using an array as my primary variable :
fields['baacf872-d554-4125-95e2-b16cdf3dd8f3'] = "GIST" or fields['4e213f7d-7be9-45c5-bb8c-0431351bd0dd'] = "GIST"
Hello 😃,
You're right, an identifier cannot start by an integer. An identifier is defined as:
%token identifier [^\s\(\)\[\],\.]+
(see the grammar)
So it should match a text starting by an integer, but this is last defined. Therefore, we look at previous tokens, we see:
%token float \d+\.\d+
%token integer \d+
So if you have 4.2
, it will be the token float
, if you have 42
, it will the token integer
, and if you have 42foobar
, it will be two tokens: integer
and identifier
, as you expect.
My recommendation would be to prefix your variables, by _
for instance.