define(function(require, exports, module) { "use strict"; var oop = require("../lib/oop"); var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules; var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules; var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*"; var GraylogRuleLangHighlightRules = function() { //TODO generate from grammar var keywords = ( "all|either|and|or|not|pipeline|rule|during|"+ "stage|when|then|end|let|match" ); //TODO generate from FunctionRegistry var builtinFunctions = ( "to_bool|to_double|to_long|to_string|to_url|is_null|"+ "is_not_null|abbreviate|capitalize|uncapitalize|uppercase|"+ "lowercase|swapcase|contains|substring|concat|split|regex|"+ "grok|key_value|crc32|crc32c|md5|murmur3_32|murmur3_128|sha1|"+ "sha256|sha512|parse_json|select_jsonpath|to_ip|cidr_match|"+ "from_input|route_to_stream|create_message|clone_message|"+ "drop_message|has_field|remove_field|set_field|set_fields|"+ "rename_field|syslog_facility|syslog_level|expand_syslog_priority|"+ "expand_syslog_priority_as_string|now|parse_date|flex_parse_date|"+ "format_date|to_date|years|months|weeks|days|hours|minutes|seconds|"+ "millis|period" ); var keywordMapper = this.createKeywordMapper({ "variable.language": "$message", "keyword": keywords, "constant.language": "null", "support.function" : builtinFunctions }, "identifier", true); //true = case insensitive // regexp must not have capturing parentheses. Use (?:) instead. // regexps are ordered -> the first match is used var stringRules = function() { return [{ token : "string", // single line with backticks regex : "[``](?:(?:\\\\.)|(?:[^`\\\\]))*?[``]" },{ token : "string", // single line double quotes regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]' }, { token : "string", // single line single quotes regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']" }]; }; var basicPreRules = function(blockCommentRules) { return [{ token : "comment", regex : "\\/\\/.*$" }, DocCommentHighlightRules.getStartRule("doc-start"), { token : "comment", // multi line comment regex : "\\/\\*", next : blockCommentRules }, { token : "constant.numeric", // hex regex : "0[xX][0-9a-fA-F]+\\b" }, { token : "constant.numeric", // float regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b" }, { token : "constant.language.boolean", regex : "(?:true|false)\\b" }]; }; var blockCommentRules = function(returnRule) { return [ { token : "comment.block", // closing comment regex : ".*?\\*\\/", next : returnRule }, { token : "comment.block", // comment spanning whole line regex : ".+" } ]; } var basicPostRules = function() { return [{ token : keywordMapper, // TODO: Unicode escape sequences // TODO: Unicode identifiers regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b" }, { token : "keyword.operator", regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=" }, { token : "lparen", regex : "[[({]" }, { token : "rparen", regex : "[\\])}]" }, { token : "text", regex : "\\s+" }]; }; this.$rules = { "start" : [].concat(basicPreRules("block.comment"), [ { // declare trait DeclaredType token : ["keyword","text","keyword","text","entity.name.type"], regex : "(declare)(\\s+)(trait)(\\s+)(" + identifierRe +")" }, { // declare trait DeclaredType token : ["keyword","text","entity.name.type"], regex : "(declare)(\\s+)(" + identifierRe +")" }, { // rule ... token : ["keyword","text"], regex : "(rule)(\\s+)", next : "asset.name" }], stringRules(), [{ // variable : token : ["variable.other","text","text"], regex : "(" + identifierRe + ")(\\s*)(:)" }, { // when ... token : ["keyword","text"], regex : "(when)(\\s*)" }, { // then token : ["keyword","text"], regex : "(then)(\\s*)", }, { token : "paren.lparen", regex : /[\[({]/ }, { token : "paren.rparen", regex : /[\])}]/ }], basicPostRules()), "block.comment" : blockCommentRules("start") }; this.embedRules(DocCommentHighlightRules, "doc-", [ DocCommentHighlightRules.getEndRule("start") ]); }; oop.inherits(GraylogRuleLangHighlightRules, TextHighlightRules); exports.GraylogRuleLangHighlightRules = GraylogRuleLangHighlightRules; });