Skip to content

Commit

Permalink
feat: add markup and fix comment markup
Browse files Browse the repository at this point in the history
* Fix comment markup (quoting comment with ```)
* Using functions and search command from Splunk Enterprise 8.1.3
  • Loading branch information
swsoyee committed Apr 19, 2021
1 parent 98b237b commit 828b833
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 31 deletions.
8 changes: 4 additions & 4 deletions dist/spl.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "highlightjs-spl",
"version": "0.1.1",
"version": "0.1.2",
"description": "highlight.js syntax definition for the Splunk search processing language (SPL).",
"main": "src/languages/spl.js",
"scripts": {
Expand Down
90 changes: 67 additions & 23 deletions src/languages/spl.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ function either(...args) {

/** @type LanguageFn */
export default function(hljs) {
const HASH_COMMENT_MODE = hljs.COMMENT('//', /$/);
const HASH_COMMENT_MODE = hljs.COMMENT('```', '```');

// List of evaluation functions from Splunk Enterprise 8.1.3 - Alphabetical list of functions
// https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/CommonEvalFunctions#Alphabetical_list_of_functions
const EVAL_FUNCTIONS = [
"abs",
"acos",
Expand All @@ -63,6 +65,7 @@ export default function(hljs) {
"cosh",
"exact",
"exp",
"false",
"floor",
"hypot",
"if",
Expand All @@ -73,10 +76,17 @@ export default function(hljs) {
"isnull",
"isnum",
"isstr",
"json_object",
"json_array",
"json_extract",
"json_keys",
"json_set",
"json_valid",
"len",
"like",
"ln",
"log",
"lookup",
"ln",
"lower",
"ltrim",
"match",
Expand All @@ -90,6 +100,7 @@ export default function(hljs) {
"mvfind",
"mvindex",
"mvjoin",
"mvmap",
"mvrange",
"mvsort",
"mvzip",
Expand Down Expand Up @@ -123,45 +134,49 @@ export default function(hljs) {
"tonumber",
"tostring",
"trim",
"true",
"typeof",
"upper",
"urldecode",
"validate"
];

// List of statistical and charting functions from Splunk Enterprise 8.1.3 - Alphabetical list of functions
// https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/CommonEvalFunctions#Alphabetical_list_of_functions
const TRANSFORMING_FUNCTIONS = [
"avg",
"count",
"distinct_count",
"earliest",
"earliest_time",
"estdc",
"estdc_error",
"eval",
"first",
"last",
"latest",
"latest_time",
"list",
"max",
"mean",
"median",
"min",
"mode",
"percentile",
"per_day",
"per_hour",
"per_minute",
"per_second",
"range",
"rate",
"rate_avg",
"rate_sum",
"stdev",
"stdevp",
"sum",
"sumsq",
"var",
"varp",
"first",
"last",
"list",
"values",
"earliest",
"earliest_time",
"latest",
"latest_time",
"per_day",
"per_hour",
"per_minute",
"per_second",
"rate"
"var",
"varp"
];

const FUNCTIONS = [
Expand All @@ -177,7 +192,8 @@ export default function(hljs) {
}
};

// https://docs.splunk.com/Documentation/SplunkLight/7.3.6/References/Listofsearchcommands
// List of search command from Splunk Enterprise 8.1.3 - Search Commands
// https://docs.splunk.com/Documentation/Splunk/8.1.3/SearchReference/WhatsInThisManual
const BUILT_IN = [
"abstract",
"accum",
Expand All @@ -187,32 +203,37 @@ export default function(hljs) {
"analyzefields",
"anomalies",
"anomalousvalue",
"anomalydetection",
"append",
"appendcols",
"appendpipe",
"arules",
"associate",
"audit",
"autoregress",
"awssnsalert",
"bin",
"bucket",
"bucketdir",
"cefout",
"chart",
"cluster",
"cofilter",
"collect",
"concurrency",
"contingency",
"convert",
"correlate",
"crawl",
"ctable",
"datamodel",
"datamodelsimple",
"dbinspect",
"dbxquery",
"dbxlookup",
"dedup",
"delete",
"delta",
"diff",
"dispatch",
"entitymerge",
"erex",
"eval",
"eventcount",
Expand All @@ -221,7 +242,6 @@ export default function(hljs) {
"fieldformat",
"fields",
"fieldsummary",
"file",
"filldown",
"fillnull",
"findtypes",
Expand All @@ -231,12 +251,15 @@ export default function(hljs) {
"from",
"gauge",
"gentimes",
"geom",
"geomfilter",
"geostats",
"head",
"highlight",
"history",
"input",
"iconify",
"inputcsv",
"inputintelligence",
"inputlookup",
"iplocation",
"join",
Expand All @@ -250,8 +273,13 @@ export default function(hljs) {
"makemv",
"makeresults",
"map",
"mcollect",
"metadata",
"metasearch",
"meventcollect",
"mpreview",
"msearch",
"mstats",
"multikv",
"multisearch",
"mvcombine",
Expand All @@ -266,11 +294,13 @@ export default function(hljs) {
"predict",
"rangemap",
"rare",
"redistribute",
"regex",
"relevancy",
"reltime",
"rename",
"replace",
"require",
"rest",
"return",
"reverse",
Expand All @@ -291,6 +321,10 @@ export default function(hljs) {
"sistats",
"sitimechart",
"sitop",
"snowincident",
"snowincidentstream",
"snowevent",
"snoweventstream",
"sort",
"spath",
"stats",
Expand All @@ -300,6 +334,7 @@ export default function(hljs) {
"tags",
"tail",
"timechart",
"timewrap",
"top",
"transaction",
"transpose",
Expand All @@ -309,13 +344,22 @@ export default function(hljs) {
"typeahead",
"typelearner",
"typer",
"union",
"uniq",
"untable",
"walklex",
"where",
"x11",
"xmlkv",
"xmlunescape",
"xpath",
"xsDisplayConcept",
"xsDisplayContext",
"xsFindBestConcept",
"xsListConcepts",
"xsListContexts",
"xsUpdateDDContext",
"xsWhere",
"xyseries"
];

Expand Down
2 changes: 1 addition & 1 deletion test/detect/default.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index="tutorialdata_access" // load dataset
index="tutorialdata_access" ```load dataset```
| reverse
| streamstats current=f global=f window=1 first(bytes) as pre_bytes by JSESSIONID
| eval diff_bytes=abs(bytes-pre_bytes)
Expand Down
2 changes: 1 addition & 1 deletion test/markup/default.expect.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index=<span class="hljs-string">&quot;tutorialdata_access&quot;</span> <span class="hljs-comment">// load dataset</span>
index=<span class="hljs-string">&quot;tutorialdata_access&quot;</span> <span class="hljs-comment">```load dataset```</span>
<span class="hljs-operator">|</span> <span class="hljs-built_in">reverse</span>
<span class="hljs-operator">|</span> <span class="hljs-built_in">streamstats</span> current=f global=f window=<span class="hljs-number">1</span> <span class="hljs-function"><span class="hljs-keyword">first</span>(</span>bytes) <span class="hljs-keyword">as</span> pre_bytes <span class="hljs-keyword">by</span> JSESSIONID
<span class="hljs-operator">|</span> <span class="hljs-built_in">eval</span> diff_bytes=<span class="hljs-function"><span class="hljs-keyword">abs</span>(</span>bytes-pre_bytes)
Expand Down
2 changes: 1 addition & 1 deletion test/markup/default.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
index="tutorialdata_access" // load dataset
index="tutorialdata_access" ```load dataset```
| reverse
| streamstats current=f global=f window=1 first(bytes) as pre_bytes by JSESSIONID
| eval diff_bytes=abs(bytes-pre_bytes)
Expand Down

0 comments on commit 828b833

Please sign in to comment.