js.spec icon indicating copy to clipboard operation
js.spec copied to clipboard

Initial work on rep *

Open davidnormo opened this issue 8 years ago • 10 comments

Just opening this PR now to get some feedback. A quick question: what name did you want to use for * - I'm leaning towards zeroOrMore but that is quite verbose. There is also rep used in places and kleene.

Work in progress.

davidnormo avatar Apr 12 '17 17:04 davidnormo

Coverage Status

Changes Unknown when pulling a85864e809ea35ab36aa9254e03b53b15eddf022 on davidnormo:12-regex-ops into ** on prayerslayer:12-regex-ops**.

coveralls avatar Apr 12 '17 17:04 coveralls

#12

davidnormo avatar Apr 12 '17 18:04 davidnormo

Wow, thanks a lot for taking the time! It'll take a while until I can look over it thoroughly, possibly next Monday?

I named * kleene because that's how they call this operator in the regex derivative paper. For sake of consistency I'd like to stick with that in the js.spec code, but we don't necessarily have to export it under this name.

As for what's missing, but you probably know this yourself, I'd like to see support for other specs (like map) and especially other combining specs like and/or as well as nilable.

Do you think we can reuse your code to build +? Maybe that's already a step too far ahead, but good to keep in mind, I don't know.

prayerslayer avatar Apr 12 '17 20:04 prayerslayer

Sure, I'm going try and tidy up a bit, so hopefully it's in a reasonable state for you to review.

Yep, I need to add the other bits and pieces in (and/or etc).

I'll have a think about +

davidnormo avatar Apr 12 '17 23:04 davidnormo

I think I'm a bit closer, at least kleeneDeriv seems to match the logic in the paper. But still trying to work out how to wrap the return value (see running test).

davidnormo avatar Apr 13 '17 16:04 davidnormo

Coverage Status

Changes Unknown when pulling 503ffda5ea5a80f97357a4f5446a420c11dde1a3 on davidnormo:12-regex-ops into ** on prayerslayer:12-regex-ops**.

coveralls avatar Apr 13 '17 16:04 coveralls

@prayerslayer So I've finally got kleene in a working state - will need a bit of clean up.

I've found a couple of problems though:

  1. I'm confused around your usage of null and undefined. Clojure only has nil and doesn't have undefined args such as: (s/conform (s/* int?)) => ArityExecption - missing 2nd arg. However in JS such a call will result in the 2nd arg becoming the value undefined. Are we treating null and undefined the same? IMO we should treat null as the value and undefined as an error. For example:
conform(kleene(int)) // invalid
conform(kleene(int), undefined) // invalid
conform(kleene(int), null) // []
conform(kleene(int), []) // []
conform(kleene(int), [null]) // invalid
conform(kleene(nilable(int)), [null]) // [null]
conform(kleene(int), [undefined]) // invalid
conform(kleene(nilable(int)), [undefined]) // invalid
  1. In some places js.spec diverges from clojure.spec - I'm not sure if that is intentional or not? For example named maybe regex? And regexes not failing when given extra input?

davidnormo avatar Apr 18 '17 16:04 davidnormo

Are we treating null and undefined the same?

That's what I tried to do until now, yes. Both have the semantic "value does not exist." But I'm open for arguments to change it, it might not hold well with nilable, repeatable things.

In some places js.spec diverges from clojure.spec

Could you provide a specific example? I'm not sure I follow.

prayerslayer avatar Apr 20 '17 06:04 prayerslayer

Hello folks! any progress on this one?

arichiardi avatar Nov 16 '17 17:11 arichiardi

@arichiardi I've not had time to look at this and doubt I will in the near future. If that changes I'd love to help out more. Apologies!

davidnormo avatar Nov 18 '17 00:11 davidnormo