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

Or method enhancements #4

Open
metal3d opened this issue Aug 13, 2013 · 3 comments
Open

Or method enhancements #4

metal3d opened this issue Aug 13, 2013 · 3 comments

Comments

@metal3d
Copy link
Member

metal3d commented Aug 13, 2013

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)$)
@brudgers
Copy link
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.hscsec.cnwrote:

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
.

@metal3d
Copy link
Member Author

metal3d commented Aug 16, 2013

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

@metal3d
Copy link
Member Author

metal3d commented Aug 16, 2013

This is as I did in my branch:

https://github.com/metal3d/GoVerbalExpressions/blob/and-or-implementation/verbalexpressions.go#L329

See Or() and And() methods that accept VerbalExpression Objects as argument. My test:
https://github.com/metal3d/GoVerbalExpressions/blob/and-or-implementation/verbalexpressions_test.go#L545
works like a charm.

Other Test for basic "Or":
https://github.com/metal3d/GoVerbalExpressions/blob/and-or-implementation/verbalexpressions_test.go#L259
where I create new object as argument (Or(new...))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants