Commit 4cebf34c835f135e51c92885d69943d32cef792a

Michael Schmidt 2021-11-22T13:04:59

Bro: Removed `variable` and minor improvements (#3186)

diff --git a/components/prism-bro.js b/components/prism-bro.js
index daa80e0..775d589 100644
--- a/components/prism-bro.js
+++ b/components/prism-bro.js
@@ -16,29 +16,18 @@ Prism.languages.bro = {
 	'boolean': /\b[TF]\b/,
 
 	'function': {
-		pattern: /(?:event|function|hook) \w+(?:::\w+)?/,
-		inside: {
-			keyword: /^(?:event|function|hook)/
-		}
-	},
-
-	'variable': {
-		pattern: /(?:global|local) \w+/i,
-		inside: {
-			keyword: /(?:global|local)/
-		}
+		pattern: /(\b(?:event|function|hook)[ \t]+)\w+(?:::\w+)?/,
+		lookbehind: true
 	},
 
 	'builtin': /(?:@(?:load(?:-(?:plugin|sigs))?|unload|prefixes|ifn?def|else|(?:end)?if|DIR|FILENAME))|(?:&?(?:add_func|create_expire|default|delete_func|encrypt|error_handler|expire_func|group|log|mergeable|optional|persistent|priority|raw_output|read_expire|redef|rotate_interval|rotate_size|synchronized|type_column|write_expire))/,
 
 	'constant': {
-		pattern: /const \w+/i,
-		inside: {
-			keyword: /const/
-		}
+		pattern: /(\bconst[ \t]+)\w+/i,
+		lookbehind: true
 	},
 
-	'keyword': /\b(?:add|addr|alarm|any|bool|break|continue|count|delete|double|else|enum|export|file|for|function|if|in|int|interval|module|next|of|opaque|pattern|port|print|record|return|schedule|set|string|subnet|table|time|timeout|using|vector|when)\b/,
+	'keyword': /\b(?:add|addr|alarm|any|bool|break|const|continue|count|delete|double|else|enum|event|export|file|for|function|global|hook|if|in|int|interval|local|module|next|of|opaque|pattern|port|print|record|return|schedule|set|string|subnet|table|time|timeout|using|vector|when)\b/,
 
 	'operator': /--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,
 
diff --git a/components/prism-bro.min.js b/components/prism-bro.min.js
index 4aecb39..bf0c7ed 100644
--- a/components/prism-bro.min.js
+++ b/components/prism-bro.min.js
@@ -1 +1 @@
-Prism.languages.bro={comment:{pattern:/(^|[^\\$])#.*/,lookbehind:!0,inside:{italic:/\b(?:FIXME|TODO|XXX)\b/}},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},boolean:/\b[TF]\b/,function:{pattern:/(?:event|function|hook) \w+(?:::\w+)?/,inside:{keyword:/^(?:event|function|hook)/}},variable:{pattern:/(?:global|local) \w+/i,inside:{keyword:/(?:global|local)/}},builtin:/(?:@(?:load(?:-(?:plugin|sigs))?|unload|prefixes|ifn?def|else|(?:end)?if|DIR|FILENAME))|(?:&?(?:add_func|create_expire|default|delete_func|encrypt|error_handler|expire_func|group|log|mergeable|optional|persistent|priority|raw_output|read_expire|redef|rotate_interval|rotate_size|synchronized|type_column|write_expire))/,constant:{pattern:/const \w+/i,inside:{keyword:/const/}},keyword:/\b(?:add|addr|alarm|any|bool|break|continue|count|delete|double|else|enum|export|file|for|function|if|in|int|interval|module|next|of|opaque|pattern|port|print|record|return|schedule|set|string|subnet|table|time|timeout|using|vector|when)\b/,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
+Prism.languages.bro={comment:{pattern:/(^|[^\\$])#.*/,lookbehind:!0,inside:{italic:/\b(?:FIXME|TODO|XXX)\b/}},string:{pattern:/(["'])(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,greedy:!0},boolean:/\b[TF]\b/,function:{pattern:/(\b(?:event|function|hook)[ \t]+)\w+(?:::\w+)?/,lookbehind:!0},builtin:/(?:@(?:load(?:-(?:plugin|sigs))?|unload|prefixes|ifn?def|else|(?:end)?if|DIR|FILENAME))|(?:&?(?:add_func|create_expire|default|delete_func|encrypt|error_handler|expire_func|group|log|mergeable|optional|persistent|priority|raw_output|read_expire|redef|rotate_interval|rotate_size|synchronized|type_column|write_expire))/,constant:{pattern:/(\bconst[ \t]+)\w+/i,lookbehind:!0},keyword:/\b(?:add|addr|alarm|any|bool|break|const|continue|count|delete|double|else|enum|event|export|file|for|function|global|hook|if|in|int|interval|local|module|next|of|opaque|pattern|port|print|record|return|schedule|set|string|subnet|table|time|timeout|using|vector|when)\b/,operator:/--?|\+\+?|!=?=?|<=?|>=?|==?=?|&&|\|\|?|\?|\*|\/|~|\^|%/,number:/\b0x[\da-f]+\b|(?:\b\d+(?:\.\d*)?|\B\.\d+)(?:e[+-]?\d+)?/i,punctuation:/[{}[\];(),.:]/};
\ No newline at end of file
diff --git a/tests/languages/bro/function_feature.test b/tests/languages/bro/function_feature.test
index a10d792..a46f9ab 100644
--- a/tests/languages/bro/function_feature.test
+++ b/tests/languages/bro/function_feature.test
@@ -8,14 +8,14 @@ event foo::bar
 ----------------------------------------------------
 
 [
-	["function", [["keyword", "function"], " foo"]],
-	["function", [["keyword", "hook"], " foo"]],
-	["function", [["keyword", "event"], " foo"]],
-	["function", [["keyword", "function"], " foo::bar"]],
-	["function", [["keyword", "hook"], " foo::bar"]],
-	["function", [["keyword", "event"], " foo::bar"]]
+	["keyword", "function"], ["function", "foo"],
+	["keyword", "hook"], ["function", "foo"],
+	["keyword", "event"], ["function", "foo"],
+	["keyword", "function"], ["function", "foo::bar"],
+	["keyword", "hook"], ["function", "foo::bar"],
+	["keyword", "event"], ["function", "foo::bar"]
 ]
 
 ----------------------------------------------------
 
-Checks for the function feature
\ No newline at end of file
+Checks for the function feature
diff --git a/tests/languages/bro/variable_feature.test b/tests/languages/bro/variable_feature.test
index daf5120..f84b66e 100644
--- a/tests/languages/bro/variable_feature.test
+++ b/tests/languages/bro/variable_feature.test
@@ -7,14 +7,23 @@ local baz = 66;
 ----------------------------------------------------
 
 [
-	["variable", [["keyword", "local"], " foo"]],
-	["variable", [["keyword", "global"], " foo"]],
-	["variable", [["keyword", "local"], " bool"]],
+	["keyword", "local"],
+	" foo\r\n",
+
+	["keyword", "global"],
+	" foo\r\n",
+
+	["keyword", "local"],
+	["keyword", "bool"],
 	["operator", "="],
 	["boolean", "T"],
 	["punctuation", ";"],
-	["constant", [["keyword", "const"], " bar"]],
-	["variable", [["keyword", "local"], " baz"]],
+
+	["keyword", "const"],
+	["constant", "bar"],
+
+	["keyword", "local"],
+	" baz ",
 	["operator", "="],
 	["number", "66"],
 	["punctuation", ";"]
@@ -22,4 +31,4 @@ local baz = 66;
 
 ----------------------------------------------------
 
-Checks for the highlighting of variables
\ No newline at end of file
+Checks for the highlighting of variables