ceylon.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /*
  2. Language: Ceylon
  3. Author: Lucas Werkmeister <mail@lucaswerkmeister.de>
  4. Website: https://ceylon-lang.org
  5. */
  6. /** @type LanguageFn */
  7. function ceylon(hljs) {
  8. // 2.3. Identifiers and keywords
  9. const KEYWORDS = [
  10. "assembly",
  11. "module",
  12. "package",
  13. "import",
  14. "alias",
  15. "class",
  16. "interface",
  17. "object",
  18. "given",
  19. "value",
  20. "assign",
  21. "void",
  22. "function",
  23. "new",
  24. "of",
  25. "extends",
  26. "satisfies",
  27. "abstracts",
  28. "in",
  29. "out",
  30. "return",
  31. "break",
  32. "continue",
  33. "throw",
  34. "assert",
  35. "dynamic",
  36. "if",
  37. "else",
  38. "switch",
  39. "case",
  40. "for",
  41. "while",
  42. "try",
  43. "catch",
  44. "finally",
  45. "then",
  46. "let",
  47. "this",
  48. "outer",
  49. "super",
  50. "is",
  51. "exists",
  52. "nonempty"
  53. ];
  54. // 7.4.1 Declaration Modifiers
  55. const DECLARATION_MODIFIERS = [
  56. "shared",
  57. "abstract",
  58. "formal",
  59. "default",
  60. "actual",
  61. "variable",
  62. "late",
  63. "native",
  64. "deprecated",
  65. "final",
  66. "sealed",
  67. "annotation",
  68. "suppressWarnings",
  69. "small"
  70. ];
  71. // 7.4.2 Documentation
  72. const DOCUMENTATION = [
  73. "doc",
  74. "by",
  75. "license",
  76. "see",
  77. "throws",
  78. "tagged"
  79. ];
  80. const SUBST = {
  81. className: 'subst',
  82. excludeBegin: true,
  83. excludeEnd: true,
  84. begin: /``/,
  85. end: /``/,
  86. keywords: KEYWORDS,
  87. relevance: 10
  88. };
  89. const EXPRESSIONS = [
  90. {
  91. // verbatim string
  92. className: 'string',
  93. begin: '"""',
  94. end: '"""',
  95. relevance: 10
  96. },
  97. {
  98. // string literal or template
  99. className: 'string',
  100. begin: '"',
  101. end: '"',
  102. contains: [ SUBST ]
  103. },
  104. {
  105. // character literal
  106. className: 'string',
  107. begin: "'",
  108. end: "'"
  109. },
  110. {
  111. // numeric literal
  112. className: 'number',
  113. begin: '#[0-9a-fA-F_]+|\\$[01_]+|[0-9_]+(?:\\.[0-9_](?:[eE][+-]?\\d+)?)?[kMGTPmunpf]?',
  114. relevance: 0
  115. }
  116. ];
  117. SUBST.contains = EXPRESSIONS;
  118. return {
  119. name: 'Ceylon',
  120. keywords: {
  121. keyword: KEYWORDS.concat(DECLARATION_MODIFIERS),
  122. meta: DOCUMENTATION
  123. },
  124. illegal: '\\$[^01]|#[^0-9a-fA-F]',
  125. contains: [
  126. hljs.C_LINE_COMMENT_MODE,
  127. hljs.COMMENT('/\\*', '\\*/', { contains: [ 'self' ] }),
  128. {
  129. // compiler annotation
  130. className: 'meta',
  131. begin: '@[a-z]\\w*(?::"[^"]*")?'
  132. }
  133. ].concat(EXPRESSIONS)
  134. };
  135. }
  136. module.exports = ceylon;