export const languageConfiguration = { wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\@\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g, comments: { lineComment: '--', blockComment: ['/*', '*/'] as [string, string], }, brackets: [ ['{', '}'], ['[', ']'], ['(', ')'], ] as any, autoClosingPairs: [ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' }, { open: '"', close: '"' }, { open: "'", close: "'" }, { open: '`', close: '`' }, ] as any, surroundingPairs: [ { open: '{', close: '}' }, { open: '[', close: ']' }, { open: '(', close: ')' }, { open: '"', close: '"' }, { open: "'", close: "'" }, { open: '`', close: '`' }, ] as any, folding: { offSide: false, }, }; // SQL keywords const keywords = [ 'SELECT', 'FROM', 'WHERE', 'AND', 'OR', 'NOT', 'JOIN', 'INNER', 'LEFT', 'RIGHT', 'FULL', 'OUTER', 'ON', 'ORDER', 'BY', 'GROUP', 'HAVING', 'LIMIT', 'OFFSET', 'INSERT', 'INTO', 'VALUES', 'UPDATE', 'SET', 'DELETE', 'CREATE', 'TABLE', 'ALTER', 'DROP', 'PRIMARY', 'KEY', 'FOREIGN', 'CONSTRAINT', 'UNIQUE', 'INDEX', 'VIEW', 'DATABASE', 'SCHEMA', 'AS', 'DISTINCT', 'CASE', 'WHEN', 'THEN', 'ELSE', 'END', 'CAST', 'BETWEEN', 'IN', 'LIKE', 'IS', 'NULL', 'TRUE', 'FALSE', 'WITH', 'UNION', 'EXCEPT', 'INTERSECT', ]; export const language = { defaultToken: '', tokenPostfix: '.sql', ignoreCase: true, brackets: [ { open: '(', close: ')', token: 'delimiter.parenthesis' }, { open: '{', close: '}', token: 'delimiter.curly' }, { open: '[', close: ']', token: 'delimiter.square' }, ], keywords, operators: ['=', '>', '<', '!', '%', '&', '|', '^', '~', '?', ':', '+', '-', '*', '/'], builtinFunctions: [ 'COUNT', 'SUM', 'AVG', 'MIN', 'MAX', 'UPPER', 'LOWER', 'LENGTH', 'SUBSTRING', 'TRIM', 'ROUND', 'ABS', 'COALESCE', 'NULLIF', 'IFNULL', 'CONCAT', 'DATE', 'NOW', 'YEAR', 'MONTH', 'DAY', 'HOUR', 'MINUTE', 'SECOND', ], escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, digits: /\d+(_+\d+)*/, octaldigits: /[0-7]+(_+[0-7]+)*/, hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/, regexpctl: /[(){}\[\]\|;,.?*+^$\\]/, regexpattern: /(\{[0-9]+\})|(\{[0-9]*,[0-9]*\})|(\?(?:\?)?|[*+]|\^|\$|\|\\)/, tokenizer: { root: [ { include: '@comments' }, { include: '@whitespace' }, { include: '@pseudo-columns' }, [/[;,.]/, 'delimiter'], [/[{}()\[\]]/, '@brackets'], { include: '@builtinVariables' }, { include: '@numbers' }, { include: '@strings' }, [/[a-zA-Z_#][a-zA-Z0-9_$#@]*(?=\s*\()/, { cases: { '@builtinFunctions': 'keyword.function', '@default': 'identifier.function' } }], [ /[a-zA-Z_#][a-zA-Z0-9_$#@]*/, { cases: { '@keywords': 'keyword', '@default': 'identifier', }, }, ], [/[<>=!%&+\-*/|~^]/, 'operator'], ], whitespace: [[/\s+/, 'white']], comments: [ [/--+.*/, 'comment'], [/\/\*/, { token: 'comment.quote', next: '@comment' }], ], comment: [ [/[^*/]+/, 'comment'], [/\*\//, { token: 'comment.quote', next: '@pop' }], [/./, 'comment'], ], 'pseudo-columns': [ [ /[$][A-Za-z_][A-Za-z0-9_]*/, { cases: { '@keywords': 'keyword', '@default': 'variable', }, }, ], [ /@[A-Za-z_][A-Za-z0-9_]*/, { cases: { '@keywords': 'keyword', '@default': 'variable', }, }, ], ], builtinVariables: [ [ /@@?[a-zA-Z_][a-zA-Z0-9_]*/, { cases: { '@keywords': 'keyword', '@default': 'variable', }, }, ], ], numbers: [ [/0[xX][0-9a-fA-F]*[0-9a-fA-F]/, 'number.hex'], [/0[0-7]+(?!\d)/, 'number.octal'], [/(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?/, 'number'], ], strings: [ [/'/, { token: 'string', next: '@string' }], [/"/, { token: 'string.double', next: '@string_double' }], [/`/, { token: 'string.backtick', next: '@string_backtick' }], ], string: [ [/[^'\\]+/, 'string'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/'/, { token: 'string', next: '@pop' }], ], string_double: [ [/[^"\\]+/, 'string.double'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/"/, { token: 'string.double', next: '@pop' }], ], string_backtick: [ [/[^`\\]+/, 'string.backtick'], [/@escapes/, 'string.escape'], [/\\./, 'string.escape.invalid'], [/`/, { token: 'string.backtick', next: '@pop' }], ], }, };