source: node_modules/refractor/lang/promql.js

main
Last change on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 2.9 KB
Line 
1'use strict'
2
3module.exports = promql
4promql.displayName = 'promql'
5promql.aliases = []
6function promql(Prism) {
7 // Thanks to: https://github.com/prometheus-community/monaco-promql/blob/master/src/promql/promql.ts
8 // As well as: https://kausal.co/blog/slate-prism-add-new-syntax-promql/
9 ;(function (Prism) {
10 // PromQL Aggregation Operators
11 // (https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators)
12 var aggregations = [
13 'sum',
14 'min',
15 'max',
16 'avg',
17 'group',
18 'stddev',
19 'stdvar',
20 'count',
21 'count_values',
22 'bottomk',
23 'topk',
24 'quantile'
25 ] // PromQL vector matching + the by and without clauses
26 // (https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching)
27 var vectorMatching = [
28 'on',
29 'ignoring',
30 'group_right',
31 'group_left',
32 'by',
33 'without'
34 ] // PromQL offset modifier
35 // (https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier)
36 var offsetModifier = ['offset']
37 var keywords = aggregations.concat(vectorMatching, offsetModifier)
38 Prism.languages.promql = {
39 comment: {
40 pattern: /(^[ \t]*)#.*/m,
41 lookbehind: true
42 },
43 'vector-match': {
44 // Match the comma-separated label lists inside vector matching:
45 pattern: new RegExp(
46 '((?:' + vectorMatching.join('|') + ')\\s*)\\([^)]*\\)'
47 ),
48 lookbehind: true,
49 inside: {
50 'label-key': {
51 pattern: /\b[^,]+\b/,
52 alias: 'attr-name'
53 },
54 punctuation: /[(),]/
55 }
56 },
57 'context-labels': {
58 pattern: /\{[^{}]*\}/,
59 inside: {
60 'label-key': {
61 pattern: /\b[a-z_]\w*(?=\s*(?:=|![=~]))/,
62 alias: 'attr-name'
63 },
64 'label-value': {
65 pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/,
66 greedy: true,
67 alias: 'attr-value'
68 },
69 punctuation: /\{|\}|=~?|![=~]|,/
70 }
71 },
72 'context-range': [
73 {
74 pattern: /\[[\w\s:]+\]/,
75 // [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+/,
86 // offset 1m
87 lookbehind: true,
88 inside: {
89 'range-duration': {
90 pattern: /\b(?:\d+(?:[smhdwy]|ms))+\b/i,
91 alias: 'number'
92 }
93 }
94 }
95 ],
96 keyword: new RegExp('\\b(?:' + keywords.join('|') + ')\\b', 'i'),
97 function: /\b[a-z_]\w*(?=\s*\()/i,
98 number:
99 /[-+]?(?:(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[-+]?\d+)?\b|\b(?:0x[0-9a-f]+|nan|inf)\b)/i,
100 operator: /[\^*/%+-]|==|!=|<=|<|>=|>|\b(?:and|or|unless)\b/i,
101 punctuation: /[{};()`,.[\]]/
102 }
103 })(Prism)
104}
Note: See TracBrowser for help on using the repository browser.