Skip to content

Commit 42fcf6c

Browse files
committed
refactor: remove dependency of highligh.js/libs
1 parent afc13ec commit 42fcf6c

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

src/languages/spl.js

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,41 @@ Description: language definition for Splunk search processing language (SPL)
55
Category: enterprise
66
*/
77

8-
import * as regex from '../lib/regex.js';
8+
// === Start ===
9+
// Functions from highlight.js/lib/regex.js
10+
// Source: https://github.com/highlightjs/highlight.js/blob/main/src/lib/regex.js
11+
/**
12+
* @param {RegExp | string } re
13+
* @returns {string}
14+
*/
15+
function source(re) {
16+
if (!re) return null;
17+
if (typeof re === "string") return re;
18+
19+
return re.source;
20+
}
21+
22+
/**
23+
* @param {...(RegExp | string) } args
24+
* @returns {string}
25+
*/
26+
function concat(...args) {
27+
const joined = args.map((x) => source(x)).join("");
28+
return joined;
29+
}
30+
31+
/**
32+
* Any of the passed expresssions may match
33+
*
34+
* Creates a huge this | this | that | that match
35+
* @param {(RegExp | string)[] } args
36+
* @returns {string}
37+
*/
38+
function either(...args) {
39+
const joined = '(' + args.map((x) => source(x)).join("|") + ")";
40+
return joined;
41+
}
42+
// === End ===
943

1044
/** @type LanguageFn */
1145
export default function(hljs) {
@@ -137,7 +171,7 @@ export default function(hljs) {
137171

138172
const FUNCTION_CALL = {
139173
className: 'function',
140-
begin: regex.concat(/\b/, regex.either(...FUNCTIONS), /\s*\(/),
174+
begin: concat(/\b/, either(...FUNCTIONS), /\s*\(/),
141175
keywords: {
142176
keyword: FUNCTIONS
143177
}

0 commit comments

Comments
 (0)