1package s
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 . "github.com/alecthomas/chroma/lexers/circular" // nolint
6 "github.com/alecthomas/chroma/lexers/internal"
7)
8
9// Smarty lexer.
10var Smarty = internal.Register(MustNewLexer(
11 &Config{
12 Name: "Smarty",
13 Aliases: []string{"smarty"},
14 Filenames: []string{"*.tpl"},
15 MimeTypes: []string{"application/x-smarty"},
16 DotAll: true,
17 },
18 Rules{
19 "root": {
20 {`[^{]+`, Other, nil},
21 {`(\{)(\*.*?\*)(\})`, ByGroups(CommentPreproc, Comment, CommentPreproc), nil},
22 {`(\{php\})(.*?)(\{/php\})`, ByGroups(CommentPreproc, Using(PHP), CommentPreproc), nil},
23 {`(\{)(/?[a-zA-Z_]\w*)(\s*)`, ByGroups(CommentPreproc, NameFunction, Text), Push("smarty")},
24 {`\{`, CommentPreproc, Push("smarty")},
25 },
26 "smarty": {
27 {`\s+`, Text, nil},
28 {`\{`, CommentPreproc, Push()},
29 {`\}`, CommentPreproc, Pop(1)},
30 {`#[a-zA-Z_]\w*#`, NameVariable, nil},
31 {`\$[a-zA-Z_]\w*(\.\w+)*`, NameVariable, nil},
32 {`[~!%^&*()+=|\[\]:;,.<>/?@-]`, Operator, nil},
33 {`(true|false|null)\b`, KeywordConstant, nil},
34 {`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
35 {`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
36 {`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
37 {`[a-zA-Z_]\w*`, NameAttribute, nil},
38 },
39 },
40))