...

Source file src/github.com/alecthomas/chroma/lexers/h/handlebars.go

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

     1  package h
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Handlebars lexer.
     9  var Handlebars = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Handlebars",
    12  		Aliases:   []string{"handlebars", "hbs"},
    13  		Filenames: []string{"*.handlebars", "*.hbs"},
    14  		MimeTypes: []string{},
    15  	},
    16  	handlebarsRules,
    17  ))
    18  
    19  func handlebarsRules() Rules {
    20  	return Rules{
    21  		"root": {
    22  			{`[^{]+`, Other, nil},
    23  			{`\{\{!.*\}\}`, Comment, nil},
    24  			{`(\{\{\{)(\s*)`, ByGroups(CommentSpecial, Text), Push("tag")},
    25  			{`(\{\{)(\s*)`, ByGroups(CommentPreproc, Text), Push("tag")},
    26  		},
    27  		"tag": {
    28  			{`\s+`, Text, nil},
    29  			{`\}\}\}`, CommentSpecial, Pop(1)},
    30  			{`\}\}`, CommentPreproc, Pop(1)},
    31  			{`([#/]*)(each|if|unless|else|with|log|in(?:line)?)`, ByGroups(Keyword, Keyword), nil},
    32  			{`#\*inline`, Keyword, nil},
    33  			{`([#/])([\w-]+)`, ByGroups(NameFunction, NameFunction), nil},
    34  			{`([\w-]+)(=)`, ByGroups(NameAttribute, Operator), nil},
    35  			{`(>)(\s*)(@partial-block)`, ByGroups(Keyword, Text, Keyword), nil},
    36  			{`(#?>)(\s*)([\w-]+)`, ByGroups(Keyword, Text, NameVariable), nil},
    37  			{`(>)(\s*)(\()`, ByGroups(Keyword, Text, Punctuation), Push("dynamic-partial")},
    38  			Include("generic"),
    39  		},
    40  		"dynamic-partial": {
    41  			{`\s+`, Text, nil},
    42  			{`\)`, Punctuation, Pop(1)},
    43  			{`(lookup)(\s+)(\.|this)(\s+)`, ByGroups(Keyword, Text, NameVariable, Text), nil},
    44  			{`(lookup)(\s+)(\S+)`, ByGroups(Keyword, Text, UsingSelf("variable")), nil},
    45  			{`[\w-]+`, NameFunction, nil},
    46  			Include("generic"),
    47  		},
    48  		"variable": {
    49  			{`[a-zA-Z][\w-]*`, NameVariable, nil},
    50  			{`\.[\w-]+`, NameVariable, nil},
    51  			{`(this\/|\.\/|(\.\.\/)+)[\w-]+`, NameVariable, nil},
    52  		},
    53  		"generic": {
    54  			Include("variable"),
    55  			{`:?"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
    56  			{`:?'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
    57  			{`[0-9](\.[0-9]*)?(eE[+-][0-9])?[flFLdD]?|0[xX][0-9a-fA-F]+[Ll]?`, LiteralNumber, nil},
    58  		},
    59  	}
    60  }
    61  

View as plain text