CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
java.js292 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/*37Language: Java38Author: Vsevolod Solovyov <vsevolod.solovyov@gmail.com>39Category: common, enterprise40Website: https://www.java.com/41*/42 43 44/**45 * Allows recursive regex expressions to a given depth46 *47 * ie: recurRegex("(abc~~~)", /~~~/g, 2) becomes:48 * (abc(abc(abc)))49 *50 * @param {string} re51 * @param {RegExp} substitution (should be a g mode regex)52 * @param {number} depth53 * @returns {string}``54 */55function recurRegex(re, substitution, depth) {56  if (depth === -1) return "";57 58  return re.replace(substitution, _ => {59    return recurRegex(re, substitution, depth - 1);60  });61}62 63/** @type LanguageFn */64function java(hljs) {65  const regex = hljs.regex;66  const JAVA_IDENT_RE = '[\u00C0-\u02B8a-zA-Z_$][\u00C0-\u02B8a-zA-Z_$0-9]*';67  const GENERIC_IDENT_RE = JAVA_IDENT_RE68    + recurRegex('(?:<' + JAVA_IDENT_RE + '~~~(?:\\s*,\\s*' + JAVA_IDENT_RE + '~~~)*>)?', /~~~/g, 2);69  const MAIN_KEYWORDS = [70    'synchronized',71    'abstract',72    'private',73    'var',74    'static',75    'if',76    'const ',77    'for',78    'while',79    'strictfp',80    'finally',81    'protected',82    'import',83    'native',84    'final',85    'void',86    'enum',87    'else',88    'break',89    'transient',90    'catch',91    'instanceof',92    'volatile',93    'case',94    'assert',95    'package',96    'default',97    'public',98    'try',99    'switch',100    'continue',101    'throws',102    'protected',103    'public',104    'private',105    'module',106    'requires',107    'exports',108    'do',109    'sealed',110    'yield',111    'permits',112    'goto',113    'when'114  ];115 116  const BUILT_INS = [117    'super',118    'this'119  ];120 121  const LITERALS = [122    'false',123    'true',124    'null'125  ];126 127  const TYPES = [128    'char',129    'boolean',130    'long',131    'float',132    'int',133    'byte',134    'short',135    'double'136  ];137 138  const KEYWORDS = {139    keyword: MAIN_KEYWORDS,140    literal: LITERALS,141    type: TYPES,142    built_in: BUILT_INS143  };144 145  const ANNOTATION = {146    className: 'meta',147    begin: '@' + JAVA_IDENT_RE,148    contains: [149      {150        begin: /\(/,151        end: /\)/,152        contains: [ "self" ] // allow nested () inside our annotation153      }154    ]155  };156  const PARAMS = {157    className: 'params',158    begin: /\(/,159    end: /\)/,160    keywords: KEYWORDS,161    relevance: 0,162    contains: [ hljs.C_BLOCK_COMMENT_MODE ],163    endsParent: true164  };165 166  return {167    name: 'Java',168    aliases: [ 'jsp' ],169    keywords: KEYWORDS,170    illegal: /<\/|#/,171    contains: [172      hljs.COMMENT(173        '/\\*\\*',174        '\\*/',175        {176          relevance: 0,177          contains: [178            {179              // eat up @'s in emails to prevent them to be recognized as doctags180              begin: /\w+@/,181              relevance: 0182            },183            {184              className: 'doctag',185              begin: '@[A-Za-z]+'186            }187          ]188        }189      ),190      // relevance boost191      {192        begin: /import java\.[a-z]+\./,193        keywords: "import",194        relevance: 2195      },196      hljs.C_LINE_COMMENT_MODE,197      hljs.C_BLOCK_COMMENT_MODE,198      {199        begin: /"""/,200        end: /"""/,201        className: "string",202        contains: [ hljs.BACKSLASH_ESCAPE ]203      },204      hljs.APOS_STRING_MODE,205      hljs.QUOTE_STRING_MODE,206      {207        match: [208          /\b(?:class|interface|enum|extends|implements|new)/,209          /\s+/,210          JAVA_IDENT_RE211        ],212        className: {213          1: "keyword",214          3: "title.class"215        }216      },217      {218        // Exceptions for hyphenated keywords219        match: /non-sealed/,220        scope: "keyword"221      },222      {223        begin: [224          regex.concat(/(?!else)/, JAVA_IDENT_RE),225          /\s+/,226          JAVA_IDENT_RE,227          /\s+/,228          /=(?!=)/229        ],230        className: {231          1: "type",232          3: "variable",233          5: "operator"234        }235      },236      {237        begin: [238          /record/,239          /\s+/,240          JAVA_IDENT_RE241        ],242        className: {243          1: "keyword",244          3: "title.class"245        },246        contains: [247          PARAMS,248          hljs.C_LINE_COMMENT_MODE,249          hljs.C_BLOCK_COMMENT_MODE250        ]251      },252      {253        // Expression keywords prevent 'keyword Name(...)' from being254        // recognized as a function definition255        beginKeywords: 'new throw return else',256        relevance: 0257      },258      {259        begin: [260          '(?:' + GENERIC_IDENT_RE + '\\s+)',261          hljs.UNDERSCORE_IDENT_RE,262          /\s*(?=\()/263        ],264        className: { 2: "title.function" },265        keywords: KEYWORDS,266        contains: [267          {268            className: 'params',269            begin: /\(/,270            end: /\)/,271            keywords: KEYWORDS,272            relevance: 0,273            contains: [274              ANNOTATION,275              hljs.APOS_STRING_MODE,276              hljs.QUOTE_STRING_MODE,277              NUMERIC,278              hljs.C_BLOCK_COMMENT_MODE279            ]280          },281          hljs.C_LINE_COMMENT_MODE,282          hljs.C_BLOCK_COMMENT_MODE283        ]284      },285      NUMERIC,286      ANNOTATION287    ]288  };289}290 291export { java as default };292 
basant307/AI_Governance_Project · CoolFace