...

Source file src/github.com/alecthomas/chroma/lexers/m/mako.go

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

     1  package m
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  	. "github.com/alecthomas/chroma/lexers/p" // nolint
     7  )
     8  
     9  // Mako lexer.
    10  var Mako = internal.Register(MustNewLazyLexer(
    11  	&Config{
    12  		Name:      "Mako",
    13  		Aliases:   []string{"mako"},
    14  		Filenames: []string{"*.mao"},
    15  		MimeTypes: []string{"application/x-mako"},
    16  	},
    17  	makoRules,
    18  ))
    19  
    20  func makoRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`(\s*)(%)(\s*end(?:\w+))(\n|\Z)`, ByGroups(Text, CommentPreproc, Keyword, Other), nil},
    24  			{`(\s*)(%)([^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Using(Python), Other), nil},
    25  			{`(\s*)(##[^\n]*)(\n|\Z)`, ByGroups(Text, CommentPreproc, Other), nil},
    26  			{`(?s)<%doc>.*?</%doc>`, CommentPreproc, nil},
    27  			{`(<%)([\w.:]+)`, ByGroups(CommentPreproc, NameBuiltin), Push("tag")},
    28  			{`(</%)([\w.:]+)(>)`, ByGroups(CommentPreproc, NameBuiltin, CommentPreproc), nil},
    29  			{`<%(?=([\w.:]+))`, CommentPreproc, Push("ondeftags")},
    30  			{`(<%(?:!?))(.*?)(%>)(?s)`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
    31  			{`(\$\{)(.*?)(\})`, ByGroups(CommentPreproc, Using(Python), CommentPreproc), nil},
    32  			{`(?sx)
    33                  (.+?)                # anything, followed by:
    34                  (?:
    35                   (?<=\n)(?=%|\#\#) | # an eval or comment line
    36                   (?=\#\*) |          # multiline comment
    37                   (?=</?%) |          # a python block
    38                                       # call start or end
    39                   (?=\$\{) |          # a substitution
    40                   (?<=\n)(?=\s*%) |
    41                                       # - don't consume
    42                   (\\\n) |            # an escaped newline
    43                   \Z                  # end of string
    44                  )
    45              `, ByGroups(Other, Operator), nil},
    46  			{`\s+`, Text, nil},
    47  		},
    48  		"ondeftags": {
    49  			{`<%`, CommentPreproc, nil},
    50  			{`(?<=<%)(include|inherit|namespace|page)`, NameBuiltin, nil},
    51  			Include("tag"),
    52  		},
    53  		"tag": {
    54  			{`((?:\w+)\s*=)(\s*)(".*?")`, ByGroups(NameAttribute, Text, LiteralString), nil},
    55  			{`/?\s*>`, CommentPreproc, Pop(1)},
    56  			{`\s+`, Text, nil},
    57  		},
    58  		"attr": {
    59  			{`".*?"`, LiteralString, Pop(1)},
    60  			{`'.*?'`, LiteralString, Pop(1)},
    61  			{`[^\s>]+`, LiteralString, Pop(1)},
    62  		},
    63  	}
    64  }
    65  

View as plain text