If key of ctx has prefix "and" or "or" for function Execute, it errors
mingwho opened this issue · 3 comments
import (
"log"
"os"
"github.com/tyler-sommer/stick"
)
func main() {
env := stick.New(nil)
if err := env.Execute("Hello, {{ order }}!", os.Stdout, map[string]stick.Value{"order": "ABCD"}); err != nil {
log.Fatal(err)
}
}
Something like this causes error parse: unexpected token "OPERATOR" on line 1, column 10
I think this is due to this line
Line 18 in 0563422
The regex here just checks the start of the string and matches the entire string. To match the keyword exactly you can try using:
operatorMatcher = regexp.MustCompile(`^(not in|not|\*\*|is not|//|>=|<=|` + strings.Join(ops, "|") + ")$")
With $
sign at the end the match should be exact.
I think this is due to this line
Line 18 in 0563422
The regex here just checks the start of the string and matches the entire string. To match the keyword exactly you can try using:
operatorMatcher = regexp.MustCompile(`^(not in|not|\*\*|is not|//|>=|<=|` + strings.Join(ops, "|") + ")$")With
$
sign at the end the match should be exact.
I tried adding the $
sign at the end of the regex expression, it causes some other tests to fail. As an alternative solution, I'm updating the lexer so it checks for extra space after operator if we match the string and if operator is alphabetic (this is because we still want something like {{ 1*2 }} to work). Pls check this PR #24
Resolved