gval icon indicating copy to clipboard operation
gval copied to clipboard

Allow dashes in identfiers

Open TomTheBear opened this issue 2 years ago • 1 comments

I have the case that one of my identifiers contains a -, like type-id. The parser fails because - is not an allowed rune in an identifier.

Example:

func main() {
    vars := map[string]interface{}{"type-id": "4"}
    expr := `type-id == "4"`
    e, err := gval.Full().NewEvaluable(expr)
    if err != nil {
        return
    }
    value, err := e.EvalBool(context.Background(), vars)
    if err != nil {
        return
    }
    fmt.Println(value)
}

I could open a PR, but the fix is so simple: Add the condition (pos > 0 && r == '-') to https://github.com/PaesslerAG/gval/blob/master/parser.go#L33 . The example works, I tested it even for multiple dashes. But I'm new to gval, so I might miss some cases.

TomTheBear avatar Jun 12 '22 15:06 TomTheBear