mirror of
https://github.com/alecthomas/chroma.git
synced 2025-02-13 13:28:27 +02:00
Support comma in go template (e.g. for range)
``` {{ range $idx, $value := $variable }} Hello {{ $idx }} {{ end }} ```
This commit is contained in:
parent
6665753f98
commit
42e9638ed4
@ -80,7 +80,7 @@ var goTemplateRules = Rules{
|
||||
{`\s+`, Whitespace, nil},
|
||||
{`\(`, Operator, Push("subexpression")},
|
||||
{`(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},
|
||||
{`\||:?=|,`, Operator, nil},
|
||||
{`[$]?[^\W\d]\w*`, NameOther, nil},
|
||||
{`[$]?\.(?:[^\W\d]\w*)?`, NameAttribute, nil},
|
||||
{`"(\\\\|\\"|[^"])*"`, LiteralString, nil},
|
||||
|
6
lexers/testdata/go-text-template.actual
vendored
6
lexers/testdata/go-text-template.actual
vendored
@ -3,4 +3,8 @@
|
||||
*/}}
|
||||
|
||||
{{ $myVar := 2 }}
|
||||
{{ $myVar = 4 }}
|
||||
{{ $myVar = 4 }}
|
||||
|
||||
{{ range $idx, $value := $variable }}
|
||||
Hello {{ $idx }}
|
||||
{{ end }}
|
27
lexers/testdata/go-text-template.expected
vendored
27
lexers/testdata/go-text-template.expected
vendored
@ -19,5 +19,32 @@
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameOther","value":"4"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"CommentPreproc","value":"}}"},
|
||||
{"type":"Other","value":"\n\n"},
|
||||
{"type":"CommentPreproc","value":"{{"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Keyword","value":"range"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameOther","value":"$idx"},
|
||||
{"type":"Operator","value":","},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameOther","value":"$value"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Operator","value":":="},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameOther","value":"$variable"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"CommentPreproc","value":"}}"},
|
||||
{"type":"Other","value":"\nHello "},
|
||||
{"type":"CommentPreproc","value":"{{"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"NameOther","value":"$idx"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"CommentPreproc","value":"}}"},
|
||||
{"type":"Other","value":"\n"},
|
||||
{"type":"CommentPreproc","value":"{{"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"Keyword","value":"end"},
|
||||
{"type":"TextWhitespace","value":" "},
|
||||
{"type":"CommentPreproc","value":"}}"}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user