scala.js (2626B)
1 /* 2 Language: Scala 3 Category: functional 4 Author: Jan Berkel <jan.berkel@gmail.com> 5 Contributors: Erik Osheim <d_m@plastic-idolatry.com> 6 Website: https://www.scala-lang.org 7 */ 8 9 function scala(hljs) { 10 11 var ANNOTATION = { className: 'meta', begin: '@[A-Za-z]+' }; 12 13 // used in strings for escaping/interpolation/substitution 14 var SUBST = { 15 className: 'subst', 16 variants: [ 17 {begin: '\\$[A-Za-z0-9_]+'}, 18 {begin: '\\${', end: '}'} 19 ] 20 }; 21 22 var STRING = { 23 className: 'string', 24 variants: [ 25 { 26 begin: '"', end: '"', 27 illegal: '\\n', 28 contains: [hljs.BACKSLASH_ESCAPE] 29 }, 30 { 31 begin: '"""', end: '"""', 32 relevance: 10 33 }, 34 { 35 begin: '[a-z]+"', end: '"', 36 illegal: '\\n', 37 contains: [hljs.BACKSLASH_ESCAPE, SUBST] 38 }, 39 { 40 className: 'string', 41 begin: '[a-z]+"""', end: '"""', 42 contains: [SUBST], 43 relevance: 10 44 } 45 ] 46 47 }; 48 49 var SYMBOL = { 50 className: 'symbol', 51 begin: '\'\\w[\\w\\d_]*(?!\')' 52 }; 53 54 var TYPE = { 55 className: 'type', 56 begin: '\\b[A-Z][A-Za-z0-9_]*', 57 relevance: 0 58 }; 59 60 var NAME = { 61 className: 'title', 62 begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/, 63 relevance: 0 64 }; 65 66 var CLASS = { 67 className: 'class', 68 beginKeywords: 'class object trait type', 69 end: /[:={\[\n;]/, 70 excludeEnd: true, 71 contains: [ 72 { 73 beginKeywords: 'extends with', 74 relevance: 10 75 }, 76 { 77 begin: /\[/, 78 end: /\]/, 79 excludeBegin: true, 80 excludeEnd: true, 81 relevance: 0, 82 contains: [TYPE] 83 }, 84 { 85 className: 'params', 86 begin: /\(/, 87 end: /\)/, 88 excludeBegin: true, 89 excludeEnd: true, 90 relevance: 0, 91 contains: [TYPE] 92 }, 93 NAME 94 ] 95 }; 96 97 var METHOD = { 98 className: 'function', 99 beginKeywords: 'def', 100 end: /[:={\[(\n;]/, 101 excludeEnd: true, 102 contains: [NAME] 103 }; 104 105 return { 106 name: 'Scala', 107 keywords: { 108 literal: 'true false null', 109 keyword: 'type yield lazy override def with val var sealed abstract private trait object if forSome for while throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit' 110 }, 111 contains: [ 112 hljs.C_LINE_COMMENT_MODE, 113 hljs.C_BLOCK_COMMENT_MODE, 114 STRING, 115 SYMBOL, 116 TYPE, 117 METHOD, 118 CLASS, 119 hljs.C_NUMBER_MODE, 120 ANNOTATION 121 ] 122 }; 123 } 124 125 module.exports = scala;