aboutsummaryrefslogtreecommitdiffstats
path: root/public/prism/prism-sql.js
blob: f0c39393d981e549e3addea4cd7ee51eded4d5ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
Prism.languages.sql = {
  comment: {
    pattern: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/|#).*)/,
    lookbehind: true,
  },
  variable: [
    {
      pattern: /@(["'`])(?:\\[\s\S]|(?!\1)[^\\])+\1/,
      greedy: true,
    },
    /@[\w.$]+/,
  ],
  string: {
    pattern: /(^|[^@\\])("|')(?:\\[\s\S]|(?!\2)[^\\]|\2\2)*\2/,
    greedy: true,
    lookbehind: true,
  },
  identifier: {
    pattern: /(^|[^@\\])`(?:\\[\s\S]|[^`\\]|``)*`/,
    greedy: true,
    lookbehind: true,
    inside: {
      punctuation: /^`|`$/,
    },
  },
  function:
    /\b(?:AVG|COUNT|FIRST|FORMAT|LAST|LCASE|LEN|MAX|MID|MIN|MOD|NOW|ROUND|SUM|UCASE)(?=\s*\()/i, // Should we highlight user defined functions too?
  keyword:
    /\b(?:ACTION|ADD|AFTER|ALGORITHM|ALL|ALTER|ANALYZE|ANY|APPLY|AS|ASC|AUTHORIZATION|AUTO_INCREMENT|BACKUP|BDB|BEGIN|BERKELEYDB|BIGINT|BINARY|BIT|BLOB|BOOL|BOOLEAN|BREAK|BROWSE|BTREE|BULK|BY|CALL|CASCADED?|CASE|CHAIN|CHAR(?:ACTER|SET)?|CHECK(?:POINT)?|CLOSE|CLUSTERED|COALESCE|COLLATE|COLUMNS?|COMMENT|COMMIT(?:TED)?|COMPUTE|CONNECT|CONSISTENT|CONSTRAINT|CONTAINS(?:TABLE)?|CONTINUE|CONVERT|CREATE|CROSS|CURRENT(?:_DATE|_TIME|_TIMESTAMP|_USER)?|CURSOR|CYCLE|DATA(?:BASES?)?|DATE(?:TIME)?|DAY|DBCC|DEALLOCATE|DEC|DECIMAL|DECLARE|DEFAULT|DEFINER|DELAYED|DELETE|DELIMITERS?|DENY|DESC|DESCRIBE|DETERMINISTIC|DISABLE|DISCARD|DISK|DISTINCT|DISTINCTROW|DISTRIBUTED|DO|DOUBLE|DROP|DUMMY|DUMP(?:FILE)?|DUPLICATE|ELSE(?:IF)?|ENABLE|ENCLOSED|END|ENGINE|ENUM|ERRLVL|ERRORS|ESCAPED?|EXCEPT|EXEC(?:UTE)?|EXISTS|EXIT|EXPLAIN|EXTENDED|FETCH|FIELDS|FILE|FILLFACTOR|FIRST|FIXED|FLOAT|FOLLOWING|FOR(?: EACH ROW)?|FORCE|FOREIGN|FREETEXT(?:TABLE)?|FROM|FULL|FUNCTION|GEOMETRY(?:COLLECTION)?|GLOBAL|GOTO|GRANT|GROUP|HANDLER|HASH|HAVING|HOLDLOCK|HOUR|IDENTITY(?:COL|_INSERT)?|IF|IGNORE|IMPORT|INDEX|INFILE|INNER|INNODB|INOUT|INSERT|INT|INTEGER|INTERSECT|INTERVAL|INTO|INVOKER|ISOLATION|ITERATE|JOIN|KEYS?|KILL|LANGUAGE|LAST|LEAVE|LEFT|LEVEL|LIMIT|LINENO|LINES|LINESTRING|LOAD|LOCAL|LOCK|LONG(?:BLOB|TEXT)|LOOP|MATCH(?:ED)?|MEDIUM(?:BLOB|INT|TEXT)|MERGE|MIDDLEINT|MINUTE|MODE|MODIFIES|MODIFY|MONTH|MULTI(?:LINESTRING|POINT|POLYGON)|NATIONAL|NATURAL|NCHAR|NEXT|NO|NONCLUSTERED|NULLIF|NUMERIC|OFF?|OFFSETS?|ON|OPEN(?:DATASOURCE|QUERY|ROWSET)?|OPTIMIZE|OPTION(?:ALLY)?|ORDER|OUT(?:ER|FILE)?|OVER|PARTIAL|PARTITION|PERCENT|PIVOT|PLAN|POINT|POLYGON|PRECEDING|PRECISION|PREPARE|PREV|PRIMARY|PRINT|PRIVILEGES|PROC(?:EDURE)?|PUBLIC|PURGE|QUICK|RAISERROR|READS?|REAL|RECONFIGURE|REFERENCES|RELEASE|RENAME|REPEAT(?:ABLE)?|REPLACE|REPLICATION|REQUIRE|RESIGNAL|RESTORE|RESTRICT|RETURN(?:ING|S)?|REVOKE|RIGHT|ROLLBACK|ROUTINE|ROW(?:COUNT|GUIDCOL|S)?|RTREE|RULE|SAVE(?:POINT)?|SCHEMA|SECOND|SELECT|SERIAL(?:IZABLE)?|SESSION(?:_USER)?|SET(?:USER)?|SHARE|SHOW|SHUTDOWN|SIMPLE|SMALLINT|SNAPSHOT|SOME|SONAME|SQL|START(?:ING)?|STATISTICS|STATUS|STRIPED|SYSTEM_USER|TABLES?|TABLESPACE|TEMP(?:ORARY|TABLE)?|TERMINATED|TEXT(?:SIZE)?|THEN|TIME(?:STAMP)?|TINY(?:BLOB|INT|TEXT)|TOP?|TRAN(?:SACTIONS?)?|TRIGGER|TRUNCATE|TSEQUAL|TYPES?|UNBOUNDED|UNCOMMITTED|UNDEFINED|UNION|UNIQUE|UNLOCK|UNPIVOT|UNSIGNED|UPDATE(?:TEXT)?|USAGE|USE|USER|USING|VALUES?|VAR(?:BINARY|CHAR|CHARACTER|YING)|VIEW|WAITFOR|WARNINGS|WHEN|WHERE|WHILE|WITH(?: ROLLUP|IN)?|WORK|WRITE(?:TEXT)?|YEAR)\b/i,
  boolean: /\b(?:FALSE|NULL|TRUE)\b/i,
  number: /\b0x[\da-f]+\b|\b\d+(?:\.\d*)?|\B\.\d+\b/i,
  operator:
    /[-+*\/=%^~]|&&?|\|\|?|!=?|<(?:=>?|<|>)?|>[>=]?|\b(?:AND|BETWEEN|DIV|ILIKE|IN|IS|LIKE|NOT|OR|REGEXP|RLIKE|SOUNDS LIKE|XOR)\b/i,
  punctuation: /[;[\]()`,.]/,
};
or: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
(function (Prism) {
  var operators = [
    // query and projection
    '$eq',
    '$gt',
    '$gte',
    '$in',
    '$lt',
    '$lte',
    '$ne',
    '$nin',
    '$and',
    '$not',
    '$nor',
    '$or',
    '$exists',
    '$type',
    '$expr',
    '$jsonSchema',
    '$mod',
    '$regex',
    '$text',
    '$where',
    '$geoIntersects',
    '$geoWithin',
    '$near',
    '$nearSphere',
    '$all',
    '$elemMatch',
    '$size',
    '$bitsAllClear',
    '$bitsAllSet',
    '$bitsAnyClear',
    '$bitsAnySet',
    '$comment',
    '$elemMatch',
    '$meta',
    '$slice',

    // update
    '$currentDate',
    '$inc',
    '$min',
    '$max',
    '$mul',
    '$rename',
    '$set',
    '$setOnInsert',
    '$unset',
    '$addToSet',
    '$pop',
    '$pull',
    '$push',
    '$pullAll',
    '$each',
    '$position',
    '$slice',
    '$sort',
    '$bit',

    // aggregation pipeline stages
    '$addFields',
    '$bucket',
    '$bucketAuto',
    '$collStats',
    '$count',
    '$currentOp',
    '$facet',
    '$geoNear',
    '$graphLookup',
    '$group',
    '$indexStats',
    '$limit',
    '$listLocalSessions',
    '$listSessions',
    '$lookup',
    '$match',
    '$merge',
    '$out',
    '$planCacheStats',
    '$project',
    '$redact',
    '$replaceRoot',
    '$replaceWith',
    '$sample',
    '$set',
    '$skip',
    '$sort',
    '$sortByCount',
    '$unionWith',
    '$unset',
    '$unwind',

    // aggregation pipeline operators
    '$abs',
    '$accumulator',
    '$acos',
    '$acosh',
    '$add',
    '$addToSet',
    '$allElementsTrue',
    '$and',
    '$anyElementTrue',
    '$arrayElemAt',
    '$arrayToObject',
    '$asin',
    '$asinh',
    '$atan',
    '$atan2',
    '$atanh',
    '$avg',
    '$binarySize',
    '$bsonSize',
    '$ceil',
    '$cmp',
    '$concat',
    '$concatArrays',
    '$cond',
    '$convert',
    '$cos',
    '$dateFromParts',
    '$dateToParts',
    '$dateFromString',
    '$dateToString',
    '$dayOfMonth',
    '$dayOfWeek',
    '$dayOfYear',
    '$degreesToRadians',
    '$divide',
    '$eq',
    '$exp',
    '$filter',
    '$first',
    '$floor',
    '$function',
    '$gt',
    '$gte',
    '$hour',
    '$ifNull',
    '$in',
    '$indexOfArray',
    '$indexOfBytes',
    '$indexOfCP',
    '$isArray',
    '$isNumber',
    '$isoDayOfWeek',
    '$isoWeek',
    '$isoWeekYear',
    '$last',
    '$last',
    '$let',
    '$literal',
    '$ln',
    '$log',
    '$log10',
    '$lt',
    '$lte',
    '$ltrim',
    '$map',
    '$max',
    '$mergeObjects',
    '$meta',
    '$min',
    '$millisecond',
    '$minute',
    '$mod',
    '$month',
    '$multiply',
    '$ne',
    '$not',
    '$objectToArray',
    '$or',
    '$pow',
    '$push',
    '$radiansToDegrees',
    '$range',
    '$reduce',
    '$regexFind',
    '$regexFindAll',
    '$regexMatch',
    '$replaceOne',
    '$replaceAll',
    '$reverseArray',
    '$round',
    '$rtrim',
    '$second',
    '$setDifference',
    '$setEquals',
    '$setIntersection',
    '$setIsSubset',
    '$setUnion',
    '$size',
    '$sin',
    '$slice',
    '$split',
    '$sqrt',
    '$stdDevPop',
    '$stdDevSamp',
    '$strcasecmp',
    '$strLenBytes',
    '$strLenCP',
    '$substr',
    '$substrBytes',
    '$substrCP',
    '$subtract',
    '$sum',
    '$switch',
    '$tan',
    '$toBool',
    '$toDate',
    '$toDecimal',
    '$toDouble',
    '$toInt',
    '$toLong',
    '$toObjectId',
    '$toString',
    '$toLower',
    '$toUpper',
    '$trim',
    '$trunc',
    '$type',
    '$week',
    '$year',
    '$zip',

    // aggregation pipeline query modifiers
    '$comment',
    '$explain',
    '$hint',
    '$max',
    '$maxTimeMS',
    '$min',
    '$orderby',
    '$query',
    '$returnKey',
    '$showDiskLoc',
    '$natural',
  ];

  var builtinFunctions = [
    'ObjectId',
    'Code',
    'BinData',
    'DBRef',
    'Timestamp',
    'NumberLong',
    'NumberDecimal',
    'MaxKey',
    'MinKey',
    'RegExp',
    'ISODate',
    'UUID',
  ];

  operators = operators.map(function (operator) {
    return operator.replace('$', '\\$');
  });

  var operatorsSource = '(?:' + operators.join('|') + ')\\b';

  Prism.languages.mongodb = Prism.languages.extend('javascript', {});

  Prism.languages.insertBefore('mongodb', 'string', {
    property: {
      pattern:
        /(?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|(?!\s)[_$a-zA-Z\xA0-\uFFFF](?:(?!\s)[$\w\xA0-\uFFFF])*)(?=\s*:)/,
      greedy: true,
      inside: {
        keyword: RegExp('^([\'"])?' + operatorsSource + '(?:\\1)?$'),
      },
    },
  });

  Prism.languages.mongodb.string.inside = {
    url: {
      // url pattern
      pattern:
        /https?:\/\/[-\w@:%.+~#=]{1,256}\.[a-z0-9()]{1,6}\b[-\w()@:%+.~#?&/=]*/i,
      greedy: true,
    },
    entity: {
      // ipv4
      pattern:
        /\b(?:(?:[01]?\d\d?|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d\d?|2[0-4]\d|25[0-5])\b/,
      greedy: true,
    },
  };

  Prism.languages.insertBefore('mongodb', 'constant', {
    builtin: {
      pattern: RegExp('\\b(?:' + builtinFunctions.join('|') + ')\\b'),
      alias: 'keyword',
    },
  });
})(Prism);