File: smarty.go

package info (click to toggle)
golang-github-alecthomas-chroma-v2 2.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 7,980 kB
  • sloc: xml: 33,149; python: 589; javascript: 357; makefile: 36; sh: 36
file content (42 lines) | stat: -rw-r--r-- 1,262 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package lexers

import (
	. "github.com/alecthomas/chroma/v2" // nolint
)

// Smarty lexer.
var Smarty = Register(MustNewLexer(
	&Config{
		Name:      "Smarty",
		Aliases:   []string{"smarty"},
		Filenames: []string{"*.tpl"},
		MimeTypes: []string{"application/x-smarty"},
		DotAll:    true,
	},
	smartyRules,
))

func smartyRules() Rules {
	return Rules{
		"root": {
			{`[^{]+`, Other, nil},
			{`(\{)(\*.*?\*)(\})`, ByGroups(CommentPreproc, Comment, CommentPreproc), nil},
			{`(\{php\})(.*?)(\{/php\})`, ByGroups(CommentPreproc, Using("PHP"), CommentPreproc), nil},
			{`(\{)(/?[a-zA-Z_]\w*)(\s*)`, ByGroups(CommentPreproc, NameFunction, Text), Push("smarty")},
			{`\{`, CommentPreproc, Push("smarty")},
		},
		"smarty": {
			{`\s+`, Text, nil},
			{`\{`, CommentPreproc, Push()},
			{`\}`, CommentPreproc, Pop(1)},
			{`#[a-zA-Z_]\w*#`, NameVariable, nil},
			{`\$[a-zA-Z_]\w*(\.\w+)*`, NameVariable, nil},
			{`[~!%^&*()+=|\[\]:;,.<>/?@-]`, Operator, nil},
			{`(true|false|null)\b`, KeywordConstant, nil},
			{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
			{`[a-zA-Z_]\w*`, NameAttribute, nil},
		},
	}
}