github.com/pyroscope-io/pyroscope@v0.37.3-0.20230725203016-5f6947968bd0/webapp/javascript/util/prism.ts (about) 1 import Prism from 'prismjs'; 2 3 export { Prism }; 4 /* PrismJS 1.24.1 5 https://prismjs.com/download.html#themes=prism-funky&languages=promql */ 6 (function (Prism) { 7 // PromQL Aggregation Operators 8 // (https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators) 9 const aggregations = [ 10 'sum', 11 'min', 12 'max', 13 'avg', 14 'group', 15 'stddev', 16 'stdvar', 17 'count', 18 'count_values', 19 'bottomk', 20 'topk', 21 'quantile', 22 ]; 23 24 // PromQL vector matching + the by and without clauses 25 // (https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching) 26 const vectorMatching = [ 27 'on', 28 'ignoring', 29 'group_right', 30 'group_left', 31 'by', 32 'without', 33 ]; 34 35 // PromQL offset modifier 36 // (https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier) 37 const offsetModifier = ['offset']; 38 39 const keywords = aggregations.concat(vectorMatching, offsetModifier); 40 41 Prism.languages.promql = { 42 comment: { 43 pattern: /(^[ \t]*)#.*/m, 44 lookbehind: true, 45 }, 46 'vector-match': { 47 // Match the comma-separated label lists inside vector matching: 48 pattern: new RegExp(`((?:${vectorMatching.join('|')})\\s*)\\([^)]*\\)`), 49 lookbehind: true, 50 inside: { 51 'label-key': { 52 pattern: /\b[^,]+\b/, 53 alias: 'attr-name', 54 }, 55 punctuation: /[(),]/, 56 }, 57 }, 58 'context-labels': { 59 pattern: /\{[^{}]*\}/, 60 inside: { 61 'label-key': { 62 pattern: /\b[a-z_]\w*(?=\s*(?:=|![=~]))/, 63 alias: 'attr-name', 64 }, 65 'label-value': { 66 pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/, 67 greedy: true, 68 alias: 'attr-value', 69 }, 70 punctuation: /\{|\}|=~?|![=~]|,/, 71 }, 72 }, 73 'context-range': [ 74 { 75 pattern: /\[[\w\s:]+\]/, // [1m] 76 inside: { 77 punctuation: /\[|\]|:/, 78 'range-duration': { 79 pattern: /\b(?:\d+(?:[smhdwy]|ms))+\b/i, 80 alias: 'number', 81 }, 82 }, 83 }, 84 { 85 pattern: /(\boffset\s+)\w+/, // offset 1m 86 lookbehind: true, 87 inside: { 88 'range-duration': { 89 pattern: /\b(?:\d+(?:[smhdwy]|ms))+\b/i, 90 alias: 'number', 91 }, 92 }, 93 }, 94 ], 95 keyword: new RegExp(`\\b(?:${keywords.join('|')})\\b`, 'i'), 96 function: /\b[a-z_]\w*(?=\s*\()/i, 97 number: 98 /[-+]?(?:(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[-+]?\d+)?\b|\b(?:0x[0-9a-f]+|nan|inf)\b)/i, 99 operator: /[\^*/%+-]|==|!=|<=|<|>=|>|\b(?:and|or|unless)\b/i, 100 punctuation: /[{};()`,.[\]]/, 101 }; 102 })(Prism);