1
0
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:
Alberto Marchetti 2020-09-23 06:40:05 +03:00 committed by Alec Thomas
parent 6665753f98
commit 42e9638ed4
3 changed files with 33 additions and 2 deletions

View File

@ -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},

View File

@ -3,4 +3,8 @@
*/}}
{{ $myVar := 2 }}
{{ $myVar = 4 }}
{{ $myVar = 4 }}
{{ range $idx, $value := $variable }}
Hello {{ $idx }}
{{ end }}

View File

@ -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":"}}"}
]