...

Source file src/github.com/alecthomas/chroma/lexers/m/mason.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/h" // nolint
     6  	"github.com/alecthomas/chroma/lexers/internal"
     7  	. "github.com/alecthomas/chroma/lexers/p" // nolint
     8  )
     9  
    10  // Mason lexer.
    11  var Mason = internal.Register(MustNewLazyLexer(
    12  	&Config{
    13  		Name:      "Mason",
    14  		Aliases:   []string{"mason"},
    15  		Filenames: []string{"*.m", "*.mhtml", "*.mc", "*.mi", "autohandler", "dhandler"},
    16  		MimeTypes: []string{"application/x-mason"},
    17  		Priority:  0.1,
    18  	},
    19  	masonRules,
    20  ))
    21  
    22  func masonRules() Rules {
    23  	return Rules{
    24  		"root": {
    25  			{`\s+`, Text, nil},
    26  			{`(<%doc>)(.*?)(</%doc>)(?s)`, ByGroups(NameTag, CommentMultiline, NameTag), nil},
    27  			{`(<%(?:def|method))(\s*)(.*?)(>)(.*?)(</%\2\s*>)(?s)`, ByGroups(NameTag, Text, NameFunction, NameTag, UsingSelf("root"), NameTag), nil},
    28  			{`(<%\w+)(.*?)(>)(.*?)(</%\2\s*>)(?s)`, ByGroups(NameTag, NameFunction, NameTag, Using(Perl), NameTag), nil},
    29  			{`(<&[^|])(.*?)(,.*?)?(&>)(?s)`, ByGroups(NameTag, NameFunction, Using(Perl), NameTag), nil},
    30  			{`(<&\|)(.*?)(,.*?)?(&>)(?s)`, ByGroups(NameTag, NameFunction, Using(Perl), NameTag), nil},
    31  			{`</&>`, NameTag, nil},
    32  			{`(<%!?)(.*?)(%>)(?s)`, ByGroups(NameTag, Using(Perl), NameTag), nil},
    33  			{`(?<=^)#[^\n]*(\n|\Z)`, Comment, nil},
    34  			{`(?<=^)(%)([^\n]*)(\n|\Z)`, ByGroups(NameTag, Using(Perl), Other), nil},
    35  			{`(?sx)
    36                   (.+?)               # anything, followed by:
    37                   (?:
    38                    (?<=\n)(?=[%#]) |  # an eval or comment line
    39                    (?=</?[%&]) |      # a substitution or block or
    40                                       # call start or end
    41                                       # - don't consume
    42                    (\\\n) |           # an escaped newline
    43                    \Z                 # end of string
    44                   )`, ByGroups(Using(HTML), Operator), nil},
    45  		},
    46  	}
    47  }
    48  

View as plain text