...

Source file src/github.com/alecthomas/chroma/lexers/s/smarty.go

Documentation: github.com/alecthomas/chroma/lexers/s

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

View as plain text