js.spec
js.spec copied to clipboard
Initial work on rep *
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.
Changes Unknown when pulling a85864e809ea35ab36aa9254e03b53b15eddf022 on davidnormo:12-regex-ops into ** on prayerslayer:12-regex-ops**.
#12
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.
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 +
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).
Changes Unknown when pulling 503ffda5ea5a80f97357a4f5446a420c11dde1a3 on davidnormo:12-regex-ops into ** on prayerslayer:12-regex-ops**.
@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:
- I'm confused around your usage of
nullandundefined. Clojure only hasniland 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 valueundefined. Are we treatingnullandundefinedthe 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
- 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?
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.
Hello folks! any progress on this one?
@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!