Skip to content

Or method enhancements #4

Open
Open

Description

@metal3d

Still working on implementatin, I see the whole implementation (excepting mine, but I'm wrong to implement this before speaking about with you) uses this kind of method:

or(value)
=> ...|value

I'm afraid that this one is not very usefull. It can be ok for simple test, but what about finding:

startofline, then "foo", then "bar", endofline
OR
startofline, then "bar", then "baz". endofline

My implementation does:

StartOfLine().Then("foo").Then("bar").EndOfLine().Or().StartOfLine().Then("bar").Then("baz").EndOfLine()

That returns:

(?m)(?:^(?:foo)(?:bar)$)|(?:^(?:bar)(?:baz)$)

I only record an array of "parts" to concatanate at compile time... My unittest work as expected.

That works with simple expressions, or multiple expressions...

Find("foo").Or().Find("bar")
(?m)(?:foo)|(?:bar)

StartOfLine().Then("foo").Then("bar").EndOfLine().
Or().StartOfLine().Then("bar").Then("baz").EndOfLine().
Or().StartOfLine().Find("AAA").EndOfLine().
(?m)(?:^(?:foo)(?:bar)$)|(?:^(?:bar)(?:baz)$)|(?:^(?:AAA)$)

Activity

  1. brudgers commented on Aug 13, 2013

    @brudgers
    Member

    The right implementation of or is ambiguous.

    Should it be capable of implementation like this?

    (verbal-Expression-0
    (or
    (Verbal-Expression-1)
    (Verbal-Expression-2)
    (Verbal-Expression-3) )
    Verbal-Expression-4)

    Or must it be implemented like this?

    (Verbal-Expression-0)
    (or)
    (Verbal-Expression-1))

    The first requires or to accept at least two arguments.

    If or accepts no arguments then it has to be the second form. That's the
    way of the original implementation.

    I went around this with the Racket implementation which currently is a
    macro that does the second but with further work could implement the first.

    Ben

    On Tue, Aug 13, 2013 at 7:12 AM, Patrice Ferlet notifications@github.comwrote:

    Still working on implementatin, I see the whole implementation (excepting
    mine, but I'm wrong to implement this before speaking about with you) uses
    this kind of method:

    or(value)
    => ...|value

    I'm afraid that this one is not very usefull. It can be ok for simple
    test, but what about finding:

    startofline, then "foo", then "bar", endofline
    OR
    startofline, then "bar", then "baz". endofline

    My implementation does:

    StartOfLine().Then("foo").Then("bar").EndOfLine().Or().StartOfLine().Then("bar").Then("baz").EndOfLine()

    That returns:

    (?m)(?:^(?:foo)(?:bar)$)|(?: ^(?:bar)(?:baz)$)

    I only records an array of "parts" to concatanate at compile time... My
    unittest work as expected.

    —
    Reply to this email directly or view it on GitHubhttps://github.com//issues/4
    .

  2. metal3d commented on Aug 16, 2013

    @metal3d
    MemberAuthor

    Sorry for the late answer, I was out for 2 days.
    You're right, my implementation is not fully effective.

    With my implementation, this tests:

    A.(B+C)
    

    should be call with distributed form:

    (A+B) . (A+C)
    

    "A" is evaluated 2 times if B is false

    I like your idea but I dislike the fact to have "var args" (optionnal argument) (certainly because I develop with Go :))

    I have got another idea that is (I guess) more effective. I think that Or() method should get a VerbalExpression object as argument. And with should add a method named "And()" that accept VerbalExpression object.

    This is an example:

    v1 = new VE().Find("B")
    v2 = new VE().Find("C").Or(v1); // (B+C)
    v = new VE().Find("A").And(v2) // A.(B+C)
    

    This should return:

    (?m)(?:A)(?:(?:B)|(?:C))
    

    This way, we can imaginate very complexe expressions that are seperated in several objects... I can prepare a branch to validate if that works

  3. metal3d commented on Aug 16, 2013

    @metal3d
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions