cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.02k stars 286 forks source link

proposal: use ~ instead of =~ for regular expression constraints #2001

Open myitcv opened 1 year ago

myitcv commented 1 year ago

Currently (per the spec), the =~ operator is defined as follows:

s =~ r is true if s matches the regular expression r.

This issue tracks changing that operator to instead be simply ~, with the same definition.

Motivation etc.

(to follow from @mpvl)

seh commented 1 year ago

What is the motivation for the change? I find that =~ goes along with other inequality operators such as <= and >=, though perhaps that analogy would argue in favor of ~=.

myitcv commented 1 year ago

What is the motivation for the change?

Thanks. I'm just in the process of creating the umbrella issues we referenced from Community Call #1, hence why some issues are a bit light on detail. I'll defer to @mpvl to flesh this out (and will add a section above to highlight that it's pending).

mpvl commented 1 year ago

@seh, one big motivation is how ugly it is to use regexps in a pattern constraint with an alias:

[X= =~"regexp"]: T
seh commented 1 year ago

I agree: That sure is ugly. I assume that you don’t like the transposed proposal any better:

[X= ~="regexp"]: T
eonpatapon commented 1 year ago

I agree it would be better in the context of pattern constraint.

I also regularly forgot if it is =~ or ~= when writing configs.

Logically I think =~ is the correct way as we also have !~. Would be awkward to have ~= and !~.

Having ~ and !~ feels ok to me.