...

Source file src/github.com/alecthomas/chroma/lexers/d/dylan.go

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

     1  package d
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Dylan lexer.
     9  var Dylan = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:            "Dylan",
    12  		Aliases:         []string{"dylan"},
    13  		Filenames:       []string{"*.dylan", "*.dyl", "*.intr"},
    14  		MimeTypes:       []string{"text/x-dylan"},
    15  		CaseInsensitive: true,
    16  	},
    17  	func() Rules {
    18  		return Rules{
    19  			"root": {
    20  				{`\s+`, Whitespace, nil},
    21  				{`//.*?\n`, CommentSingle, nil},
    22  				{`([a-z0-9-]+:)([ \t]*)(.*(?:\n[ \t].+)*)`, ByGroups(NameAttribute, Whitespace, LiteralString), nil},
    23  				Default(Push("code")),
    24  			},
    25  			"code": {
    26  				{`\s+`, Whitespace, nil},
    27  				{`//.*?\n`, CommentSingle, nil},
    28  				{`/\*`, CommentMultiline, Push("comment")},
    29  				{`"`, LiteralString, Push("string")},
    30  				{`'(\\.|\\[0-7]{1,3}|\\x[a-f0-9]{1,2}|[^\\\'\n])'`, LiteralStringChar, nil},
    31  				{`#b[01]+`, LiteralNumberBin, nil},
    32  				{`#o[0-7]+`, LiteralNumberOct, nil},
    33  				{`[-+]?(\d*\.\d+([ed][-+]?\d+)?|\d+(\.\d*)?e[-+]?\d+)`, LiteralNumberFloat, nil},
    34  				{`[-+]?\d+`, LiteralNumberInteger, nil},
    35  				{`#x[0-9a-f]+`, LiteralNumberHex, nil},
    36  
    37  				{`(\?\\?)([\w!&*<>|^$%@+~?/=-]+)(:)(token|name|variable|expression|body|case-body|\*)`,
    38  					ByGroups(Operator, NameVariable, Operator, NameBuiltin), nil},
    39  				{`(\?)(:)(token|name|variable|expression|body|case-body|\*)`,
    40  					ByGroups(Operator, Operator, NameVariable), nil},
    41  				{`(\?\\?)([\w!&*<>|^$%@+~?/=-]+)`, ByGroups(Operator, NameVariable), nil},
    42  
    43  				{`(=>|::|#\(|#\[|##|\?\?|\?=|\?|[(){}\[\],.;])`, Punctuation, nil},
    44  				{`:=`, Operator, nil},
    45  				{`#[tf]`, Literal, nil},
    46  				{`#"`, LiteralStringSymbol, Push("symbol")},
    47  				{`#[a-z0-9-]+`, Keyword, nil},
    48  				{`#(all-keys|include|key|next|rest)`, Keyword, nil},
    49  				{`[\w!&*<>|^$%@+~?/=-]+:`, KeywordConstant, nil},
    50  				{`<[\w!&*<>|^$%@+~?/=-]+>`, NameClass, nil},
    51  				{`\*[\w!&*<>|^$%@+~?/=-]+\*`, NameVariableGlobal, nil},
    52  				{`\$[\w!&*<>|^$%@+~?/=-]+`, NameConstant, nil},
    53  				{`(let|method|function)([ \t]+)([\w!&*<>|^$%@+~?/=-]+)`, ByGroups(NameBuiltin, Whitespace, NameVariable), nil},
    54  				{`(error|signal|return|break)`, NameException, nil},
    55  				{`(\\?)([\w!&*<>|^$%@+~?/=-]+)`, ByGroups(Operator, Name), nil},
    56  			},
    57  			"comment": {
    58  				{`[^*/]`, CommentMultiline, nil},
    59  				{`/\*`, CommentMultiline, Push()},
    60  				{`\*/`, CommentMultiline, Pop(1)},
    61  				{`[*/]`, CommentMultiline, nil},
    62  			},
    63  			"symbol": {
    64  				{`"`, LiteralStringSymbol, Pop(1)},
    65  				{`[^\\"]+`, LiteralStringSymbol, nil},
    66  			},
    67  			"string": {
    68  				{`"`, LiteralString, Pop(1)},
    69  				{`\\([\\abfnrtv"\']|x[a-f0-9]{2,4}|[0-7]{1,3})`, LiteralStringEscape, nil},
    70  				{`[^\\"\n]+`, LiteralString, nil},
    71  				{`\\\n`, LiteralString, nil},
    72  				{`\\`, LiteralString, nil},
    73  			},
    74  		}
    75  	},
    76  ))
    77  

View as plain text