expr icon indicating copy to clipboard operation
expr copied to clipboard

Add support for tags `expr:"..."`

Open antonmedv opened this issue 6 years ago • 4 comments

Add support for tags expr:"..." for names aliases.

type Env struct {
    Value int `expr:"value"`
}

And now it's will be possible to use value instead of Value in expressions.

antonmedv avatar Oct 10 '18 10:10 antonmedv

I quite like this. Why was this closed?

Reasno avatar Nov 20 '20 10:11 Reasno

Let’s reopen this ;)

antonmedv avatar Nov 20 '20 12:11 antonmedv

To piggyback on this enhancement I need to support sloppy expressions, so ideally I need to support "Value", "value", "VALUE", etc. as mapping to the Value field.

type Env struct {
    Value int `expr:"value, VALUE, Value"`
}

And/or

type Env struct {
    Value int `expr:"case-insensitive"`
}

I guess both would have their place, some implementations need only support specific field names, while other need to support any case insensitive variation.

marcus-orchard avatar Dec 07 '20 16:12 marcus-orchard

If you want case insensitive expressions, use ast.Parse for it.

antonmedv avatar Dec 07 '20 19:12 antonmedv