-
Notifications
You must be signed in to change notification settings - Fork 20
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
Cannot use variables where one of the keys has a dash in it. #3
Comments
If that's any help, I just tried the same test case but with an underscore and it does pass the test. public function testArrayWithUnderscoreInKeyDoesParseCorrectly()
{
$this->assertTrue($this->evaluate(
'foo_bar === [
"foo", // This is foo
"bar" // And this is bar
]',
['foo_bar' => ['foo', 'bar']]
));
} |
Hi @Fuitad! Thanks for your submission. This is actually by design. I tried to keep it as close to Javascript syntax as possible. Plus, if I plan on adding math equations in the future, the dash would be interpreted as minus (foo minus bar). I'm not sure if I'll ever implement this, but it crossed my mind. However, if you're using the latest version (0.4.0 as of writing this), you can actually redefine tokens in user-land. This would allow you to do what you want. Eg: $rule->registerToken(Tokenizer::TOKEN_VARIABLE, '[a-zA-Z_][\w-]*'); I hope this helps! |
@nicoSWD Is this no longer possible? Using |
@cnanney hi! It's still possible, but the approach has changed. It's now preferred to use composition instead of inheritance. Meaning, you'd have to create your own grammar (akin to this) and construct your own container using said grammar like this. Rule.php is extendable so you should be able to override the constructor. |
See the following test (which fails currently) for an example. Not sure if it's work-as-design or not.
Btw, awesome project!
The text was updated successfully, but these errors were encountered: