...

Source file src/github.com/alecthomas/chroma/lexers/g/groovy.go

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

     1  package g
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Groovy lexer.
     9  var Groovy = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:      "Groovy",
    12  		Aliases:   []string{"groovy"},
    13  		Filenames: []string{"*.groovy", "*.gradle"},
    14  		MimeTypes: []string{"text/x-groovy"},
    15  		DotAll:    true,
    16  	},
    17  	groovyRules,
    18  ))
    19  
    20  func groovyRules() Rules {
    21  	return Rules{
    22  		"root": {
    23  			{`#!(.*?)$`, CommentPreproc, Push("base")},
    24  			Default(Push("base")),
    25  		},
    26  		"base": {
    27  			{`^(\s*(?:[a-zA-Z_][\w.\[\]]*\s+)+?)([a-zA-Z_]\w*)(\s*)(\()`, ByGroups(UsingSelf("root"), NameFunction, Text, Operator), nil},
    28  			{`[^\S\n]+`, Text, nil},
    29  			{`//.*?\n`, CommentSingle, nil},
    30  			{`/\*.*?\*/`, CommentMultiline, nil},
    31  			{`@[a-zA-Z_][\w.]*`, NameDecorator, nil},
    32  			{`(as|assert|break|case|catch|continue|default|do|else|finally|for|if|in|goto|instanceof|new|return|switch|this|throw|try|while|in|as)\b`, Keyword, nil},
    33  			{`(abstract|const|enum|extends|final|implements|native|private|protected|public|static|strictfp|super|synchronized|throws|transient|volatile)\b`, KeywordDeclaration, nil},
    34  			{`(def|boolean|byte|char|double|float|int|long|short|void)\b`, KeywordType, nil},
    35  			{`(package)(\s+)`, ByGroups(KeywordNamespace, Text), nil},
    36  			{`(true|false|null)\b`, KeywordConstant, nil},
    37  			{`(class|interface)(\s+)`, ByGroups(KeywordDeclaration, Text), Push("class")},
    38  			{`(import)(\s+)`, ByGroups(KeywordNamespace, Text), Push("import")},
    39  			{`""".*?"""`, LiteralStringDouble, nil},
    40  			{`'''.*?'''`, LiteralStringSingle, nil},
    41  			{`"(\\\\|\\"|[^"])*"`, LiteralStringDouble, nil},
    42  			{`'(\\\\|\\'|[^'])*'`, LiteralStringSingle, nil},
    43  			{`\$/((?!/\$).)*/\$`, LiteralString, nil},
    44  			{`/(\\\\|\\"|[^/])*/`, LiteralString, nil},
    45  			{`'\\.'|'[^\\]'|'\\u[0-9a-fA-F]{4}'`, LiteralStringChar, nil},
    46  			{`(\.)([a-zA-Z_]\w*)`, ByGroups(Operator, NameAttribute), nil},
    47  			{`[a-zA-Z_]\w*:`, NameLabel, nil},
    48  			{`[a-zA-Z_$]\w*`, Name, nil},
    49  			{`[~^*!%&\[\](){}<>|+=:;,./?-]`, Operator, nil},
    50  			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
    51  			{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
    52  			{`[0-9]+L?`, LiteralNumberInteger, nil},
    53  			{`\n`, Text, nil},
    54  		},
    55  		"class": {
    56  			{`[a-zA-Z_]\w*`, NameClass, Pop(1)},
    57  		},
    58  		"import": {
    59  			{`[\w.]+\*?`, NameNamespace, Pop(1)},
    60  		},
    61  	}
    62  }
    63  

View as plain text