Code Monkey home page Code Monkey logo

Comments (4)

nicoSWD avatar nicoSWD commented on May 23, 2024 1

@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.

from php-rule-parser.

Fuitad avatar Fuitad commented on May 23, 2024

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']]
        ));
    }

from php-rule-parser.

nicoSWD avatar nicoSWD commented on May 23, 2024

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!

from php-rule-parser.

cnanney avatar cnanney commented on May 23, 2024

@nicoSWD Is this no longer possible? Using 0.6.1 and there is no longer public access to the tokenizer, and all properties are private so I can't extend Rule and add a method to access from the container.

from php-rule-parser.

Related Issues (15)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.