1package c
2
3import (
4 . "github.com/alecthomas/chroma" // nolint
5 "github.com/alecthomas/chroma/lexers/internal"
6)
7
8// Coffeescript lexer.
9var Coffeescript = internal.Register(MustNewLexer(
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 Rules{
19 "commentsandwhitespace": {
20 {`\s+`, Text, nil},
21 {`###[^#].*?###`, CommentMultiline, nil},
22 {`#(?!##[^#]).*?\n`, CommentSingle, nil},
23 },
24 "multilineregex": {
25 {`[^/#]+`, LiteralStringRegex, nil},
26 {`///([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
27 {`#\{`, LiteralStringInterpol, Push("interpoling_string")},
28 {`[/#]`, LiteralStringRegex, nil},
29 },
30 "slashstartsregex": {
31 Include("commentsandwhitespace"),
32 {`///`, LiteralStringRegex, Push("#pop", "multilineregex")},
33 {`/(?! )(\\.|[^[/\\\n]|\[(\\.|[^\]\\\n])*])+/([gim]+\b|\B)`, LiteralStringRegex, Pop(1)},
34 {`/`, Operator, nil},
35 Default(Pop(1)),
36 },
37 "root": {
38 Include("commentsandwhitespace"),
39 {`^(?=\s|/)`, Text, Push("slashstartsregex")},
40 {"\\+\\+|~|&&|\\band\\b|\\bor\\b|\\bis\\b|\\bisnt\\b|\\bnot\\b|\\?|:|\\|\\||\\\\(?=\\n)|(<<|>>>?|==?(?!>)|!=?|=(?!>)|-(?!>)|[<>+*`%&\\|\\^/])=?", Operator, Push("slashstartsregex")},
41 {`(?:\([^()]*\))?\s*[=-]>`, NameFunction, Push("slashstartsregex")},
42 {`[{(\[;,]`, Punctuation, Push("slashstartsregex")},
43 {`[})\].]`, Punctuation, nil},
44 {`(?<![.$])(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")},
45 {`(?<![.$])(true|false|yes|no|on|off|null|NaN|Infinity|undefined)\b`, KeywordConstant, nil},
46 {`(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},
47 {`[$a-zA-Z_][\w.:$]*\s*[:=]\s`, NameVariable, Push("slashstartsregex")},
48 {`@[$a-zA-Z_][\w.:$]*\s*[:=]\s`, NameVariableInstance, Push("slashstartsregex")},
49 {`@`, NameOther, Push("slashstartsregex")},
50 {`@?[$a-zA-Z_][\w$]*`, NameOther, nil},
51 {`[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?`, LiteralNumberFloat, nil},
52 {`0x[0-9a-fA-F]+`, LiteralNumberHex, nil},
53 {`[0-9]+`, LiteralNumberInteger, nil},
54 {`"""`, LiteralString, Push("tdqs")},
55 {`'''`, LiteralString, Push("tsqs")},
56 {`"`, LiteralString, Push("dqs")},
57 {`'`, LiteralString, Push("sqs")},
58 },
59 "strings": {
60 {`[^#\\\'"]+`, LiteralString, nil},
61 },
62 "interpoling_string": {
63 {`\}`, LiteralStringInterpol, Pop(1)},
64 Include("root"),
65 },
66 "dqs": {
67 {`"`, LiteralString, Pop(1)},
68 {`\\.|\'`, LiteralString, nil},
69 {`#\{`, LiteralStringInterpol, Push("interpoling_string")},
70 {`#`, LiteralString, nil},
71 Include("strings"),
72 },
73 "sqs": {
74 {`'`, LiteralString, Pop(1)},
75 {`#|\\.|"`, LiteralString, nil},
76 Include("strings"),
77 },
78 "tdqs": {
79 {`"""`, LiteralString, Pop(1)},
80 {`\\.|\'|"`, LiteralString, nil},
81 {`#\{`, LiteralStringInterpol, Push("interpoling_string")},
82 {`#`, LiteralString, nil},
83 Include("strings"),
84 },
85 "tsqs": {
86 {`'''`, LiteralString, Pop(1)},
87 {`#|\\.|\'|"`, LiteralString, nil},
88 Include("strings"),
89 },
90 },
91))