maja42 / goval

Expression evaluation in golang
MIT License
157 stars 24 forks source link

Feature: Implement Null coalescence #1

Closed maja42 closed 5 years ago

maja42 commented 6 years ago

When accessing variables like this:

var
var.field["field"][otherVar].field

It should be possible to ignore errors caused by non-existing variables and get nil instead.

Example Syntax:

var?
var.field?["field"]?[otherVar]?.field?

Make sure that it is still possible to implement the ternary operator ?: without syntax conflicts later.

maja42 commented 5 years ago

Unfortunately, this feature can not be implemented with the current architecture. For performance reasons, goval does not create an AST and instead evaluates the final result while parsing the expression.

To add null-coalescence, an architecture change (build an AST) would be the right thing to do and I don't have plans to do that in the near future.