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