You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

coffee.go 3.4KB

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