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

Multiple tests cause parser error #25

Open
wbrian-onlineed opened this issue Jun 7, 2023 · 2 comments
Open

Multiple tests cause parser error #25

wbrian-onlineed opened this issue Jun 7, 2023 · 2 comments

Comments

@wbrian-onlineed
Copy link

If a function contains more than one instance of the test function, it complains of a parse error

// example bad rule:
/a/.test('a') && /x/.test('x')

Error: "preg_match(): Unknown modifier '.'"
File: nicoswd/php-rule-parser/src/Grammar/JavaScript/Methods/Test.php
Line: 46
Function: preg_match
PHP Version: 7.4.3 (ubuntu)

I have tried reordering them, changing contents of test, and removing "i" modifier. It simply doesn't like it when there are two.

Related side issue: documentation provides use as "foo".test(/oo/i) but actual usage requires the reverse:/oo/i.test("foo")

Thanks for providing this helpful utility.

@nicoSWD
Copy link
Owner

nicoSWD commented Jun 7, 2023

Hey @wbrian-onlineed

Thank you for bringing this up. As of now, all expressions require a comparison operator. Try something like this:

 /a/.test('a') === true && /x/.test('x') === true

I know it's not very intuitive, but it's an issue that resides from where the project originally started. I will eventually fix this at some point.

Let me know if this works for you.

EDIT:
Here are some working examples:
https://github.com/nicoSWD/php-rule-parser/blob/master/tests/integration/methods/TestTest.php

@wbrian-onlineed
Copy link
Author

This does not work ;-(

I understand that there needs to be an explicit equality operator present. However, even when present, the parser does not handle two or more tests in the same rule. It will fail with PHP error "preg_match(): Unknown modifier '.'".

This test should produce the error:

$rule = new Rule('/foo/.test(foo) === true && /bar/.test(foo) === false', ['foo' => 'foo']);
var_dump($rule->isTrue()); // PHP error

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