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