...

Source file src/github.com/alecthomas/chroma/lexers/c/coffee.go

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

     1  package c
     2  
     3  import (
     4  	. "github.com/alecthomas/chroma" // nolint
     5  	"github.com/alecthomas/chroma/lexers/internal"
     6  )
     7  
     8  // Coffeescript lexer.
     9  var Coffeescript = internal.Register(MustNewLazyLexer(
    10  	&Config{
    11  		Name:         "CoffeeScript",
    12  		Aliases:      []string{"coffee-script", "coffeescript", "coffee"},
    13  		Filenames:    []string{"*.coffee"},
    14  		MimeTypes:    []string{"text/coffeescript"},
    15  		NotMultiline: true,
    16  		DotAll:       true,
    17  	},
    18  	coffeescriptRules,
    19  ))
    20  
    21  func coffeescriptRules() Rules {
    22  	return Rules{
    23  		"commentsandwhitespace": {
    24  			{`\s+`, Text, nil},
    25  			{`###[^#].*?###`, CommentMultiline, nil},
    26  			{`#(?!##[^#]).*?\n`, CommentSingle, nil},
    27  		},
    28  		"multilineregex": {
    29  			{`[^/#]+`, LiteralStringRegex, nil},
    30  			{`///([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
    31  			{`#\{`, LiteralStringInterpol, Push("interpoling_string")},
    32  			{`[/#]`, LiteralStringRegex, nil},
    33  		},
    34  		"slashstartsregex": {
    35  			Include("commentsandwhitespace"),
    36  			{`///`, LiteralStringRegex, Push("#pop", "multilineregex")},
    37  			{`/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
    38  			{`/`, Operator, nil},
    39  			Default(Pop(1)),
    40  		},
    41  		"root": {
    42  			Include("commentsandwhitespace"),
    43  			{`^(?=\s|/)`, Text, Push("slashstartsregex")},
    44  			{"\\+\\+|~|&&|\\band\\b|\\bor\\b|\\bis\\b|\\bisnt\\b|\\bnot\\b|\\?|:|\\|\\||\\\\(?=\\n)|(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\\|\\^/])=?", Operator, Push("slashstartsregex")},
    45  			{`(?:\([^()]*\))?\s*[=-]>`, NameFunction, Push("slashstartsregex")},
    46  			{`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
    47  			{`[})\].]`, Punctuation, nil},
    48  			{`(?<![.$])(for|own|in|of|while|until|loop|break|return|continue|switch|when|then|if|unless|else|throw|try|catch|finally|new|delete|typeof|instanceof|super|extends|this|class|by)\b`, Keyword, Push("slashstartsregex")},
    49  			{`(?<![.$])(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b`, KeywordConstant, nil},
    50  			{`(Array|Boolean|Date|Error|Function|Math|netscape|Number|Object|Packages|RegExp|String|sun|decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|isNaN|parseFloat|parseInt|document|window)\b`, NameBuiltin, nil},
    51  			{`[$a-zA-Z_][\w.:$]*\s*[:=]\s`, NameVariable, Push("slashstartsregex")},
    52  			{`@[$a-zA-Z_][\w.:$]*\s*[:=]\s`, NameVariableInstance, Push("slashstartsregex")},
    53  			{`@`, NameOther, Push("slashstartsregex")},
    54  			{`@?[$a-zA-Z_][\w$]*`, NameOther, nil},
    55  			{`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
    56  			{`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
    57  			{`[0-9]+`, LiteralNumberInteger, nil},
    58  			{`"""`, LiteralString, Push("tdqs")},
    59  			{`'''`, LiteralString, Push("tsqs")},
    60  			{`"`, LiteralString, Push("dqs")},
    61  			{`'`, LiteralString, Push("sqs")},
    62  		},
    63  		"strings": {
    64  			{`[^#\\\'"]+`, LiteralString, nil},
    65  		},
    66  		"interpoling_string": {
    67  			{`\}`, LiteralStringInterpol, Pop(1)},
    68  			Include("root"),
    69  		},
    70  		"dqs": {
    71  			{`"`, LiteralString, Pop(1)},
    72  			{`\\.|\'`, LiteralString, nil},
    73  			{`#\{`, LiteralStringInterpol, Push("interpoling_string")},
    74  			{`#`, LiteralString, nil},
    75  			Include("strings"),
    76  		},
    77  		"sqs": {
    78  			{`'`, LiteralString, Pop(1)},
    79  			{`#|\\.|"`, LiteralString, nil},
    80  			Include("strings"),
    81  		},
    82  		"tdqs": {
    83  			{`"""`, LiteralString, Pop(1)},
    84  			{`\\.|\'|"`, LiteralString, nil},
    85  			{`#\{`, LiteralStringInterpol, Push("interpoling_string")},
    86  			{`#`, LiteralString, nil},
    87  			Include("strings"),
    88  		},
    89  		"tsqs": {
    90  			{`'''`, LiteralString, Pop(1)},
    91  			{`#|\\.|\'|"`, LiteralString, nil},
    92  			Include("strings"),
    93  		},
    94  	}
    95  }
    96  

View as plain text