import type { languages } from 'monaco-editor'; import { Grammar } from 'prismjs'; export const languageConfiguration: languages.LanguageConfiguration = { // the default separators except `@$` wordPattern: /(-?\d*\.\d\w*)|([^`~!#%^&*()\-=+\[{\]}\\|;:'",.<>\/?\s]+)/g, brackets: [ ['{', '}'], ['(', ')'], ], autoClosingPairs: [ { open: '{', close: '}' }, { open: '(', close: ')' }, { open: '"', close: '"' }, { open: "'", close: "'" }, ], surroundingPairs: [ { open: '{', close: '}' }, { open: '(', close: ')' }, { open: '"', close: '"' }, { open: "'", close: "'" }, ], folding: {}, }; export const operators = ['=', '!=', '>', '<', '>=', '<=', '=~', '!~']; export const keywordOperators = ['=', '!=']; export const stringOperators = ['=', '!=', '=~', '!~']; export const numberOperators = ['=', '!=', '>', '<', '>=', '<=']; export const intrinsics = [ 'duration', 'kind', 'name', 'rootName', 'rootServiceName', 'status', 'statusMessage', 'traceDuration', ]; export const scopes: string[] = ['resource', 'span']; export const functions = ['avg', 'min', 'max', 'sum', 'count', 'by']; const keywords = intrinsics.concat(scopes); const statusValues = ['ok', 'unset', 'error', 'false', 'true']; export const language: languages.IMonarchLanguage = { ignoreCase: false, defaultToken: '', tokenPostfix: '.traceql', keywords, operators, statusValues, functions, symbols: /[=>~]+)\s*("([^"\n&]+)?"?|([^"\n\s&|}]+))?)/g, inside: { comment: { pattern: /#.*/, }, 'label-key': { pattern: /[a-z_.][\w./_-]*(?=\s*(=|!=|>|<|>=|<=|=~|!~))/, alias: 'attr-name', }, 'label-value': { pattern: /("(?:\\.|[^\\"])*")|(\w+)/, alias: 'attr-value', }, }, }, punctuation: /[}{&|]/, }, }, number: /\b-?\d+((\.\d*)?([eE][+-]?\d+)?)?\b/, operator: new RegExp(`/[-+*/=%^~]|&&?|\\|?\\||!=?|<(?:=>?|<|>)?|>[>=]?|`, 'i'), punctuation: /[{};()`,.]/, };