tweag / nickel

Better configuration for less
https://nickel-lang.org/
MIT License
2.23k stars 85 forks source link

Add support for constant patterns #1897

Closed yannham closed 2 months ago

yannham commented 2 months ago

This PR adds support for constant patterns, that is patterns matching specific booleans, strings, numbers or the null value. This allows to write for exampe:

match {
  "foo" => ...,
  "foo/bar" => ...,
  other => ...
}

Or

match {
  {enabled = true, ..rest} => code_path_when_enabled rest,
  {enabled = false, ..} => 'Error "Is not enabled!",
}

For destructuring, the semantics is the same as for enum tags - which are actually constants as well, but were just supported as a side effect of supporting eneral enum patterns - : a constant pattern forces the value and works as an assertion.