Skip to content

Commit e6d871d

Browse files
committed
Support lone '$' in Go templates.
1 parent c49d52b commit e6d871d

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Diff for: lexers/g/go.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func goTemplateRules() Rules {
8787
{`(range|if|else|while|with|template|end|true|false|nil|and|call|html|index|js|len|not|or|print|printf|println|urlquery|eq|ne|lt|le|gt|ge)\b`, Keyword, nil},
8888
{`\||:?=|,`, Operator, nil},
8989
{`[$]?[^\W\d]\w*`, NameOther, nil},
90-
{`[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil},
90+
{`\$|[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil},
9191
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
9292
{`-?\d+i`, LiteralNumber, nil},
9393
{`-?\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil},

Diff for: lexers/testdata/go-text-template.actual

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77

88
{{ range $idx, $value := $variable }}
99
Hello {{ $idx }}
10-
{{ end }}
10+
{{ end }}
11+
12+
{{ $ }}

Diff for: lexers/testdata/go-text-template.expected

+6
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,11 @@
4646
{"type":"TextWhitespace","value":" "},
4747
{"type":"Keyword","value":"end"},
4848
{"type":"TextWhitespace","value":" "},
49+
{"type":"CommentPreproc","value":"}}"},
50+
{"type":"Other","value":"\n\n"},
51+
{"type":"CommentPreproc","value":"{{"},
52+
{"type":"TextWhitespace","value":" "},
53+
{"type":"NameAttribute","value":"$"},
54+
{"type":"TextWhitespace","value":" "},
4955
{"type":"CommentPreproc","value":"}}"}
5056
]

0 commit comments

Comments
 (0)