1 | (function (Prism) {
|
2 |
|
3 | var operators = [
|
4 |
|
5 | '$eq', '$gt', '$gte', '$in', '$lt', '$lte', '$ne', '$nin', '$and', '$not', '$nor', '$or',
|
6 | '$exists', '$type', '$expr', '$jsonSchema', '$mod', '$regex', '$text', '$where', '$geoIntersects',
|
7 | '$geoWithin', '$near', '$nearSphere', '$all', '$elemMatch', '$size', '$bitsAllClear', '$bitsAllSet',
|
8 | '$bitsAnyClear', '$bitsAnySet', '$comment', '$elemMatch', '$meta', '$slice',
|
9 |
|
10 |
|
11 | '$currentDate', '$inc', '$min', '$max', '$mul', '$rename', '$set', '$setOnInsert', '$unset',
|
12 | '$addToSet', '$pop', '$pull', '$push', '$pullAll', '$each', '$position', '$slice', '$sort', '$bit',
|
13 |
|
14 |
|
15 | '$addFields', '$bucket', '$bucketAuto', '$collStats', '$count', '$currentOp', '$facet', '$geoNear',
|
16 | '$graphLookup', '$group','$indexStats', '$limit', '$listLocalSessions', '$listSessions', '$lookup',
|
17 | '$match', '$merge', '$out', '$planCacheStats', '$project', '$redact', '$replaceRoot', '$replaceWith',
|
18 | '$sample', '$set', '$skip', '$sort', '$sortByCount', '$unionWith', '$unset', '$unwind',
|
19 |
|
20 |
|
21 | '$abs', '$accumulator', '$acos', '$acosh', '$add', '$addToSet', '$allElementsTrue', '$and',
|
22 | '$anyElementTrue', '$arrayElemAt', '$arrayToObject', '$asin', '$asinh', '$atan', '$atan2',
|
23 | '$atanh', '$avg', '$binarySize', '$bsonSize', '$ceil', '$cmp', '$concat', '$concatArrays', '$cond',
|
24 | '$convert', '$cos', '$dateFromParts', '$dateToParts', '$dateFromString', '$dateToString', '$dayOfMonth',
|
25 | '$dayOfWeek', '$dayOfYear', '$degreesToRadians', '$divide', '$eq', '$exp', '$filter', '$first',
|
26 | '$floor', '$function', '$gt', '$gte', '$hour', '$ifNull', '$in', '$indexOfArray', '$indexOfBytes',
|
27 | '$indexOfCP', '$isArray', '$isNumber', '$isoDayOfWeek', '$isoWeek', '$isoWeekYear', '$last',
|
28 | '$last', '$let', '$literal', '$ln', '$log', '$log10', '$lt', '$lte', '$ltrim', '$map', '$max',
|
29 | '$mergeObjects', '$meta', '$min', '$millisecond', '$minute', '$mod', '$month', '$multiply', '$ne',
|
30 | '$not', '$objectToArray', '$or', '$pow', '$push', '$radiansToDegrees', '$range', '$reduce',
|
31 | '$regexFind', '$regexFindAll', '$regexMatch', '$replaceOne', '$replaceAll', '$reverseArray', '$round',
|
32 | '$rtrim', '$second', '$setDifference', '$setEquals', '$setIntersection', '$setIsSubset', '$setUnion',
|
33 | '$size', '$sin', '$slice', '$split', '$sqrt', '$stdDevPop', '$stdDevSamp', '$strcasecmp', '$strLenBytes',
|
34 | '$strLenCP', '$substr', '$substrBytes', '$substrCP', '$subtract', '$sum', '$switch', '$tan',
|
35 | '$toBool', '$toDate', '$toDecimal', '$toDouble', '$toInt', '$toLong', '$toObjectId', '$toString',
|
36 | '$toLower', '$toUpper', '$trim', '$trunc', '$type', '$week', '$year', '$zip',
|
37 |
|
38 |
|
39 | '$comment', '$explain', '$hint', '$max', '$maxTimeMS', '$min', '$orderby', '$query',
|
40 | '$returnKey', '$showDiskLoc', '$natural',
|
41 | ];
|
42 |
|
43 | var builtinFunctions = [
|
44 | 'ObjectId',
|
45 | 'Code',
|
46 | 'BinData',
|
47 | 'DBRef',
|
48 | 'Timestamp',
|
49 | 'NumberLong',
|
50 | 'NumberDecimal',
|
51 | 'MaxKey',
|
52 | 'MinKey',
|
53 | 'RegExp',
|
54 | 'ISODate',
|
55 | 'UUID',
|
56 | ];
|
57 |
|
58 | operators = operators.map(function(operator) {
|
59 | return operator.replace('$', '\\$');
|
60 | });
|
61 |
|
62 | var operatorsSource = '(?:' + operators.join('|') + ')\\b';
|
63 |
|
64 | Prism.languages.mongodb = Prism.languages.extend('javascript', {});
|
65 |
|
66 | Prism.languages.insertBefore('mongodb', 'string', {
|
67 | 'property': {
|
68 | pattern: /(?:(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1|[_$a-zA-Z\xA0-\uFFFF][$\w\xA0-\uFFFF]*)(?=\s*:)/,
|
69 | greedy: true,
|
70 | inside: {
|
71 | 'keyword': RegExp('^([\'"])?' + operatorsSource + '(?:\\1)?$')
|
72 | }
|
73 | }
|
74 | });
|
75 |
|
76 | Prism.languages.mongodb.string.inside = {
|
77 | url: {
|
78 |
|
79 | pattern: /https?:\/\/[-\w@:%.+~#=]{1,256}\.[a-z0-9()]{1,6}\b[-\w()@:%+.~#?&/=]*/i,
|
80 | greedy: true
|
81 | },
|
82 | entity: {
|
83 |
|
84 | pattern: /\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b/,
|
85 | greedy: true
|
86 | }
|
87 | };
|
88 |
|
89 | Prism.languages.insertBefore('mongodb', 'constant', {
|
90 | 'builtin': {
|
91 | pattern: RegExp('\\b(?:' + builtinFunctions.join('|') + ')\\b'),
|
92 | alias: 'keyword'
|
93 | }
|
94 | });
|
95 |
|
96 | }(Prism));
|