From df253a64c573da766cf63577855496f35d14e48a Mon Sep 17 00:00:00 2001 From: Joe Davidson Date: Fri, 28 Jul 2023 13:55:12 +0100 Subject: [PATCH] fix: allow underscores in template calls (#118) --- parser/v2/templelementparser.go | 1 + parser/v2/templelementparser_test.go | 23 ++++++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/parser/v2/templelementparser.go b/parser/v2/templelementparser.go index 77d1be3dc..07e164fe9 100644 --- a/parser/v2/templelementparser.go +++ b/parser/v2/templelementparser.go @@ -18,6 +18,7 @@ var templElementStartExpressionParams = parse.StringFrom( var templElementStartExpression = ExpressionOf(parse.StringFrom( parse.AtLeast(1, parse.StringFrom( parse.StringFrom(parse.Optional(parse.String("."))), + parse.StringFrom(parse.Optional(parse.String("_"))), parse.RuneInRanges(unicode.Letter), parse.StringFrom(parse.AtMost(255, parse.RuneInRanges(unicode.Letter, unicode.Number))), parse.StringFrom(parse.Optional(templElementStartExpressionParams)), diff --git a/parser/v2/templelementparser_test.go b/parser/v2/templelementparser_test.go index ad92c48be..b15aaf2a2 100644 --- a/parser/v2/templelementparser_test.go +++ b/parser/v2/templelementparser_test.go @@ -8,7 +8,7 @@ import ( ) func TestTemplElementExpressionParser(t *testing.T) { - var tests = []struct { + tests := []struct { name string input string expected TemplElementExpression @@ -34,6 +34,27 @@ func TestTemplElementExpressionParser(t *testing.T) { }, }, }, + { + name: "templelement: simple with underscore", + input: `@Other_Component(p.Test)` + "\n", + expected: TemplElementExpression{ + Expression: Expression{ + Value: "Other_Component(p.Test)", + Range: Range{ + From: Position{ + Index: 1, + Line: 0, + Col: 1, + }, + To: Position{ + Index: 24, + Line: 0, + Col: 24, + }, + }, + }, + }, + }, { name: "templelement: simple, block with text", input: `@Other(p.Test) {