import ace from 'brace' ; import 'brace/ext/language_tools' ; import { AceInterface } from './ace_types' ; import { getOsqueryTableNames } from './osquery_tables' ; const osqueryTables = getOsqueryTableNames ( ) . join ( '|' ) ; const keywords = [ 'select' , 'insert' , 'update' , 'delete' , 'from' , 'where' , 'and' , 'or' , 'group' , 'by' , 'order' , 'limit' , 'offset' , 'having' , 'as' , 'case' , 'when' , 'else' , 'end' , 'type' , 'left' , 'right' , 'join' , 'on' , 'outer' , 'desc' , 'asc' , 'union' , 'create' , 'table' , 'primary' , 'key' , 'if' , 'foreign' , 'not' , 'references' , 'default' , 'null' , 'inner' , 'cross' , 'natural' , 'database' , 'drop' , 'grant' , ] . join ( '|' ) ; const builtinConstants = [ 'true' , 'false' ] . join ( '|' ) ; const builtinFunctions = [ 'avg' , 'count' , 'first' , 'last' , 'max' , 'min' , 'sum' , 'ucase' , 'lcase' , 'mid' , 'len' , 'round' , 'rank' , 'now' , 'format' , 'coalesce' , 'ifnull' , 'isnull' , 'nvl' , ] . join ( '|' ) ; const dataTypes = [ 'int' , 'numeric' , 'decimal' , 'date' , 'varchar' , 'char' , 'bigint' , 'float' , 'double' , 'bit' , 'binary' , 'text' , 'set' , 'timestamp' , 'money' , 'real' , 'number' , 'integer' , ] . join ( '|' ) ; ( ace as unknown as AceInterface ) . define ( 'ace/mode/osquery_highlight_rules' , [ 'require' , 'exports' , 'ace/mode/sql_highlight_rules' ] , function ( acequire , exports ) { 'use strict' ; const SqlHighlightRules = acequire ( './sql_highlight_rules' ) . SqlHighlightRules ; class OsqueryHighlightRules extends SqlHighlightRules { constructor ( ... args ) { super ( ... args ) ; const keywordMapper = this . createKeywordMapper ( { 'osquery-token' : osqueryTables , 'support.function' : builtinFunctions , keyword : keywords , 'constant.language' : builtinConstants , 'storage.type' : dataTypes , } , 'identifier' , true ) ; this . $rules = { start : [ { token : 'comment' , regex : '--.*$' , } , { token : 'comment' , start : '/\\*' , end : '\\*/' , } , { token : 'string' , regex : '".*?"' , } , { token : 'string' , regex : "'.*?'" , } , { token : 'constant.numeric' , regex : '[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b' , } , { token : keywordMapper , regex : '[a-zA-Z_$][a-zA-Z0-9_$]*\\b' , } , { token : 'keyword.operator' , regex : '\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|=' , } , { token : 'paren.lparen' , regex : '[\\(]' , } , { token : 'paren.rparen' , regex : '[\\)]' , } , { token : 'text' , regex : '\\s+' , } , ] , } ; this . normalizeRules ( ) ; } } exports . OsqueryHighlightRules = OsqueryHighlightRules ; } ) ;