Skip to content

Commit

Permalink
Support lone '$' in Go templates.
Browse files Browse the repository at this point in the history
  • Loading branch information
alecthomas committed Feb 8, 2021
1 parent c49d52b commit e6d871d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lexers/g/go.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func goTemplateRules() Rules {
{`(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},
{`\||:?=|,`, Operator, nil},
{`[$]?[^\W\d]\w*`, NameOther, nil},
{`[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil},
{`\$|[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil},
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
{`-?\d+i`, LiteralNumber, nil},
{`-?\d+\.\d*([Ee][-+]\d+)?i`, LiteralNumber, nil},
Expand Down
4 changes: 3 additions & 1 deletion lexers/testdata/go-text-template.actual
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

{{ range $idx, $value := $variable }}
Hello {{ $idx }}
{{ end }}
{{ end }}

{{ $ }}
6 changes: 6 additions & 0 deletions lexers/testdata/go-text-template.expected
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,11 @@
{"type":"TextWhitespace","value":" "},
{"type":"Keyword","value":"end"},
{"type":"TextWhitespace","value":" "},
{"type":"CommentPreproc","value":"}}"},
{"type":"Other","value":"\n\n"},
{"type":"CommentPreproc","value":"{{"},
{"type":"TextWhitespace","value":" "},
{"type":"NameAttribute","value":"$"},
{"type":"TextWhitespace","value":" "},
{"type":"CommentPreproc","value":"}}"}
]

0 comments on commit e6d871d

Please sign in to comment.