basant307/AI_Governance_Project
048
1/*2Language: Scala3Category: functional4Author: Jan Berkel <jan.berkel@gmail.com>5Contributors: Erik Osheim <d_m@plastic-idolatry.com>6Website: https://www.scala-lang.org7*/8 9function scala(hljs) {10 const regex = hljs.regex;11 const ANNOTATION = {12 className: 'meta',13 begin: '@[A-Za-z]+'14 };15 16 // used in strings for escaping/interpolation/substitution17 const SUBST = {18 className: 'subst',19 variants: [20 { begin: '\\$[A-Za-z0-9_]+' },21 {22 begin: /\$\{/,23 end: /\}/24 }25 ]26 };27 28 const STRING = {29 className: 'string',30 variants: [31 {32 begin: '"""',33 end: '"""'34 },35 {36 begin: '"',37 end: '"',38 illegal: '\\n',39 contains: [ hljs.BACKSLASH_ESCAPE ]40 },41 {42 begin: '[a-z]+"',43 end: '"',44 illegal: '\\n',45 contains: [46 hljs.BACKSLASH_ESCAPE,47 SUBST48 ]49 },50 {51 className: 'string',52 begin: '[a-z]+"""',53 end: '"""',54 contains: [ SUBST ],55 relevance: 1056 }57 ]58 59 };60 61 const TYPE = {62 className: 'type',63 begin: '\\b[A-Z][A-Za-z0-9_]*',64 relevance: 065 };66 67 const NAME = {68 className: 'title',69 begin: /[^0-9\n\t "'(),.`{}\[\]:;][^\n\t "'(),.`{}\[\]:;]+|[^0-9\n\t "'(),.`{}\[\]:;=]/,70 relevance: 071 };72 73 const CLASS = {74 className: 'class',75 beginKeywords: 'class object trait type',76 end: /[:={\[\n;]/,77 excludeEnd: true,78 contains: [79 hljs.C_LINE_COMMENT_MODE,80 hljs.C_BLOCK_COMMENT_MODE,81 {82 beginKeywords: 'extends with',83 relevance: 1084 },85 {86 begin: /\[/,87 end: /\]/,88 excludeBegin: true,89 excludeEnd: true,90 relevance: 0,91 contains: [ 92 TYPE, 93 hljs.C_LINE_COMMENT_MODE, 94 hljs.C_BLOCK_COMMENT_MODE, 95 ]96 },97 {98 className: 'params',99 begin: /\(/,100 end: /\)/,101 excludeBegin: true,102 excludeEnd: true,103 relevance: 0,104 contains: [ 105 TYPE, 106 hljs.C_LINE_COMMENT_MODE, 107 hljs.C_BLOCK_COMMENT_MODE, 108 ]109 },110 NAME111 ]112 };113 114 const METHOD = {115 className: 'function',116 beginKeywords: 'def',117 end: regex.lookahead(/[:={\[(\n;]/),118 contains: [ NAME ]119 };120 121 const EXTENSION = {122 begin: [123 /^\s*/, // Is first token on the line124 'extension',125 /\s+(?=[[(])/, // followed by at least one space and `[` or `(`126 ],127 beginScope: { 2: "keyword", }128 };129 130 const END = {131 begin: [132 /^\s*/, // Is first token on the line133 /end/,134 /\s+/,135 /(extension\b)?/, // `extension` is the only marker that follows an `end` that cannot be captured by another rule.136 ],137 beginScope: {138 2: "keyword",139 4: "keyword",140 }141 };142 143 // TODO: use negative look-behind in future144 // /(?<!\.)\binline(?=\s)/145 const INLINE_MODES = [146 { match: /\.inline\b/ },147 {148 begin: /\binline(?=\s)/,149 keywords: 'inline'150 }151 ];152 153 const USING_PARAM_CLAUSE = {154 begin: [155 /\(\s*/, // Opening `(` of a parameter or argument list156 /using/,157 /\s+(?!\))/, // Spaces not followed by `)`158 ],159 beginScope: { 2: "keyword", }160 };161 162 // glob all non-whitespace characters as a "string"163 // sourced from https://github.com/scala/docs.scala-lang/pull/2845164 const DIRECTIVE_VALUE = {165 className: 'string',166 begin: /\S+/,167 };168 169 // directives170 // sourced from https://github.com/scala/docs.scala-lang/pull/2845171 const USING_DIRECTIVE = {172 begin: [173 '//>',174 /\s+/,175 /using/,176 /\s+/,177 /\S+/178 ],179 beginScope: {180 1: "comment",181 3: "keyword",182 5: "type"183 },184 end: /$/,185 contains: [186 DIRECTIVE_VALUE,187 ]188 };189 190 return {191 name: 'Scala',192 keywords: {193 literal: 'true false null',194 keyword: 'type yield lazy override def with val var sealed abstract private trait object if then forSome for while do throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit export enum given transparent'195 },196 contains: [197 USING_DIRECTIVE,198 hljs.C_LINE_COMMENT_MODE,199 hljs.C_BLOCK_COMMENT_MODE,200 STRING,201 TYPE,202 METHOD,203 CLASS,204 hljs.C_NUMBER_MODE,205 EXTENSION,206 END,207 ...INLINE_MODES,208 USING_PARAM_CLAUSE,209 ANNOTATION210 ]211 };212}213 214export { scala as default };215 