CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
kotlin.js287 linesDownload Raw Back to languages
1// https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.102var decimalDigits = '[0-9](_*[0-9])*';3var frac = `\\.(${decimalDigits})`;4var hexDigits = '[0-9a-fA-F](_*[0-9a-fA-F])*';5var NUMERIC = {6  className: 'number',7  variants: [8    // DecimalFloatingPointLiteral9    // including ExponentPart10    { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +11      `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },12    // excluding ExponentPart13    { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },14    { begin: `(${frac})[fFdD]?\\b` },15    { begin: `\\b(${decimalDigits})[fFdD]\\b` },16 17    // HexadecimalFloatingPointLiteral18    { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +19      `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },20 21    // DecimalIntegerLiteral22    { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },23 24    // HexIntegerLiteral25    { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },26 27    // OctalIntegerLiteral28    { begin: '\\b0(_*[0-7])*[lL]?\\b' },29 30    // BinaryIntegerLiteral31    { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },32  ],33  relevance: 034};35 36/*37 Language: Kotlin38 Description: Kotlin is an OSS statically typed programming language that targets the JVM, Android, JavaScript and Native.39 Author: Sergey Mashkov <cy6erGn0m@gmail.com>40 Website: https://kotlinlang.org41 Category: common42 */43 44 45function kotlin(hljs) {46  const KEYWORDS = {47    keyword:48      'abstract as val var vararg get set class object open private protected public noinline '49      + 'crossinline dynamic final enum if else do while for when throw try catch finally '50      + 'import package is in fun override companion reified inline lateinit init '51      + 'interface annotation data sealed internal infix operator out by constructor super '52      + 'tailrec where const inner suspend typealias external expect actual',53    built_in:54      'Byte Short Char Int Long Boolean Float Double Void Unit Nothing',55    literal:56      'true false null'57  };58  const KEYWORDS_WITH_LABEL = {59    className: 'keyword',60    begin: /\b(break|continue|return|this)\b/,61    starts: { contains: [62      {63        className: 'symbol',64        begin: /@\w+/65      }66    ] }67  };68  const LABEL = {69    className: 'symbol',70    begin: hljs.UNDERSCORE_IDENT_RE + '@'71  };72 73  // for string templates74  const SUBST = {75    className: 'subst',76    begin: /\$\{/,77    end: /\}/,78    contains: [ hljs.C_NUMBER_MODE ]79  };80  const VARIABLE = {81    className: 'variable',82    begin: '\\$' + hljs.UNDERSCORE_IDENT_RE83  };84  const STRING = {85    className: 'string',86    variants: [87      {88        begin: '"""',89        end: '"""(?=[^"])',90        contains: [91          VARIABLE,92          SUBST93        ]94      },95      // Can't use built-in modes easily, as we want to use STRING in the meta96      // context as 'meta-string' and there's no syntax to remove explicitly set97      // classNames in built-in modes.98      {99        begin: '\'',100        end: '\'',101        illegal: /\n/,102        contains: [ hljs.BACKSLASH_ESCAPE ]103      },104      {105        begin: '"',106        end: '"',107        illegal: /\n/,108        contains: [109          hljs.BACKSLASH_ESCAPE,110          VARIABLE,111          SUBST112        ]113      }114    ]115  };116  SUBST.contains.push(STRING);117 118  const ANNOTATION_USE_SITE = {119    className: 'meta',120    begin: '@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*' + hljs.UNDERSCORE_IDENT_RE + ')?'121  };122  const ANNOTATION = {123    className: 'meta',124    begin: '@' + hljs.UNDERSCORE_IDENT_RE,125    contains: [126      {127        begin: /\(/,128        end: /\)/,129        contains: [130          hljs.inherit(STRING, { className: 'string' }),131          "self"132        ]133      }134    ]135  };136 137  // https://kotlinlang.org/docs/reference/whatsnew11.html#underscores-in-numeric-literals138  // According to the doc above, the number mode of kotlin is the same as java 8,139  // so the code below is copied from java.js140  const KOTLIN_NUMBER_MODE = NUMERIC;141  const KOTLIN_NESTED_COMMENT = hljs.COMMENT(142    '/\\*', '\\*/',143    { contains: [ hljs.C_BLOCK_COMMENT_MODE ] }144  );145  const KOTLIN_PAREN_TYPE = { variants: [146    {147      className: 'type',148      begin: hljs.UNDERSCORE_IDENT_RE149    },150    {151      begin: /\(/,152      end: /\)/,153      contains: [] // defined later154    }155  ] };156  const KOTLIN_PAREN_TYPE2 = KOTLIN_PAREN_TYPE;157  KOTLIN_PAREN_TYPE2.variants[1].contains = [ KOTLIN_PAREN_TYPE ];158  KOTLIN_PAREN_TYPE.variants[1].contains = [ KOTLIN_PAREN_TYPE2 ];159 160  return {161    name: 'Kotlin',162    aliases: [163      'kt',164      'kts'165    ],166    keywords: KEYWORDS,167    contains: [168      hljs.COMMENT(169        '/\\*\\*',170        '\\*/',171        {172          relevance: 0,173          contains: [174            {175              className: 'doctag',176              begin: '@[A-Za-z]+'177            }178          ]179        }180      ),181      hljs.C_LINE_COMMENT_MODE,182      KOTLIN_NESTED_COMMENT,183      KEYWORDS_WITH_LABEL,184      LABEL,185      ANNOTATION_USE_SITE,186      ANNOTATION,187      {188        className: 'function',189        beginKeywords: 'fun',190        end: '[(]|$',191        returnBegin: true,192        excludeEnd: true,193        keywords: KEYWORDS,194        relevance: 5,195        contains: [196          {197            begin: hljs.UNDERSCORE_IDENT_RE + '\\s*\\(',198            returnBegin: true,199            relevance: 0,200            contains: [ hljs.UNDERSCORE_TITLE_MODE ]201          },202          {203            className: 'type',204            begin: /</,205            end: />/,206            keywords: 'reified',207            relevance: 0208          },209          {210            className: 'params',211            begin: /\(/,212            end: /\)/,213            endsParent: true,214            keywords: KEYWORDS,215            relevance: 0,216            contains: [217              {218                begin: /:/,219                end: /[=,\/]/,220                endsWithParent: true,221                contains: [222                  KOTLIN_PAREN_TYPE,223                  hljs.C_LINE_COMMENT_MODE,224                  KOTLIN_NESTED_COMMENT225                ],226                relevance: 0227              },228              hljs.C_LINE_COMMENT_MODE,229              KOTLIN_NESTED_COMMENT,230              ANNOTATION_USE_SITE,231              ANNOTATION,232              STRING,233              hljs.C_NUMBER_MODE234            ]235          },236          KOTLIN_NESTED_COMMENT237        ]238      },239      {240        begin: [241          /class|interface|trait/,242          /\s+/,243          hljs.UNDERSCORE_IDENT_RE244        ],245        beginScope: {246          3: "title.class"247        },248        keywords: 'class interface trait',249        end: /[:\{(]|$/,250        excludeEnd: true,251        illegal: 'extends implements',252        contains: [253          { beginKeywords: 'public protected internal private constructor' },254          hljs.UNDERSCORE_TITLE_MODE,255          {256            className: 'type',257            begin: /</,258            end: />/,259            excludeBegin: true,260            excludeEnd: true,261            relevance: 0262          },263          {264            className: 'type',265            begin: /[,:]\s*/,266            end: /[<\(,){\s]|$/,267            excludeBegin: true,268            returnEnd: true269          },270          ANNOTATION_USE_SITE,271          ANNOTATION272        ]273      },274      STRING,275      {276        className: 'meta',277        begin: "^#!/usr/bin/env",278        end: '$',279        illegal: '\n'280      },281      KOTLIN_NUMBER_MODE282    ]283  };284}285 286export { kotlin as default };287 
basant307/AI_Governance_Project · CoolFace