Skip to content

Commit

Permalink
Added support for Splunk SPL (#1962)
Browse files Browse the repository at this point in the history
This adds support for Splunk SPL and corrects the position of the SQL in `components.json`.
  • Loading branch information
RunDevelopment authored Jul 20, 2019
1 parent e8811d2 commit c93c066
Show file tree
Hide file tree
Showing 13 changed files with 446 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components.js

Large diffs are not rendered by default.

12 changes: 8 additions & 4 deletions components.json
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,19 @@
"require": "markup-templating",
"owner": "Golmote"
},
"sql": {
"title": "SQL",
"owner": "multipetros"
},
"soy": {
"title": "Soy (Closure Template)",
"require": "markup-templating",
"owner": "Golmote"
},
"splunk-spl": {
"title": "Splunk SPL",
"owner": "RunDevelopment"
},
"sql": {
"title": "SQL",
"owner": "multipetros"
},
"stylus": {
"title": "Stylus",
"owner": "vkbansal"
Expand Down
24 changes: 24 additions & 0 deletions components/prism-splunk-spl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Prism.languages['splunk-spl'] = {
'comment': /`comment\("(?:\\.|[^\\"])*"\)`/,
'string': {
pattern: /"(?:\\.|[^\\"])*"/,
greedy: true
},
// https://docs.splunk.com/Documentation/Splunk/7.3.0/SearchReference/ListOfSearchCommands
'keyword': /\b(?:abstract|accum|addcoltotals|addinfo|addtotals|analyzefields|anomalies|anomalousvalue|anomalydetection|append|appendcols|appendcsv|appendlookup|appendpipe|arules|associate|audit|autoregress|bin|bucket|bucketdir|chart|cluster|cofilter|collect|concurrency|contingency|convert|correlate|datamodel|dbinspect|dedup|delete|delta|diff|erex|eval|eventcount|eventstats|extract|fieldformat|fields|fieldsummary|filldown|fillnull|findtypes|folderize|foreach|format|from|gauge|gentimes|geom|geomfilter|geostats|head|highlight|history|iconify|input|inputcsv|inputlookup|iplocation|join|kmeans|kv|kvform|loadjob|localize|localop|lookup|makecontinuous|makemv|makeresults|map|mcollect|metadata|metasearch|meventcollect|mstats|multikv|multisearch|mvcombine|mvexpand|nomv|outlier|outputcsv|outputlookup|outputtext|overlap|pivot|predict|rangemap|rare|regex|relevancy|reltime|rename|replace|rest|return|reverse|rex|rtorder|run|savedsearch|script|scrub|search|searchtxn|selfjoin|sendemail|set|setfields|sichart|sirare|sistats|sitimechart|sitop|sort|spath|stats|strcat|streamstats|table|tags|tail|timechart|timewrap|top|transaction|transpose|trendline|tscollect|tstats|typeahead|typelearner|typer|union|uniq|untable|where|x11|xmlkv|xmlunescape|xpath|xyseries)\b/i,
'operator-word': {
pattern: /\b(?:and|as|by|not|or|xor)\b/i,
alias: 'operator'
},
'function': /\w+(?=\s*\()/,
'property': /\w+(?=\s*=(?!=))/,
'date': {
// MM/DD/YYYY(:HH:MM:SS)?
pattern: /\b\d{1,2}\/\d{1,2}\/\d{1,4}(?:(?::\d{1,2}){3})?\b/,
alias: 'number'
},
'number': /\b\d+(?:\.\d+)?\b/,
'boolean': /\b(?:f|false|t|true)\b/i,
'operator': /[<>=]=?|[-+*/%|]/,
'punctuation': /[()[\],]/
}
1 change: 1 addition & 0 deletions components/prism-splunk-spl.min.js

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

7 changes: 7 additions & 0 deletions examples/prism-splunk-spl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<h2>Full example</h2>
<pre><code>source=monthly_data.csv
| rename remote_ip AS ip
| eval isLocal=if(cidrmatch("123.132.32.0/25",ip), "local", "not local")
| eval error=case(status == 200, "OK", status == 404, "Not found", true(), "Other")
`comment("TODO: Add support for more status codes")`
| sort amount</code></pre>
3 changes: 2 additions & 1 deletion plugins/show-language/prism-show-language.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@
"sass": "Sass (Sass)",
"scss": "Sass (Scss)",
"shell-session": "Shell session",
"sql": "SQL",
"soy": "Soy (Closure Template)",
"splunk-spl": "Splunk SPL",
"sql": "SQL",
"tap": "TAP",
"toml": "TOML",
"tt2": "Template Toolkit 2",
Expand Down
2 changes: 1 addition & 1 deletion plugins/show-language/prism-show-language.min.js

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

16 changes: 16 additions & 0 deletions tests/languages/splunk-spl/comment_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
`comment("This is a comment")`
`comment("This is too
but on more than one line")`
`comment("| stats sum(b) BY index")`

----------------------------------------------------

[
["comment", "`comment(\"This is a comment\")`"],
["comment", "`comment(\"This is too\r\nbut on more than one line\")`"],
["comment", "`comment(\"| stats sum(b) BY index\")`"]
]

----------------------------------------------------

Checks for comments.
13 changes: 13 additions & 0 deletions tests/languages/splunk-spl/date_feature.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
1/1/1970
12/31/1999:23:59:59

----------------------------------------------------

[
["date", "1/1/1970"],
["date", "12/31/1999:23:59:59"]
]

----------------------------------------------------

Checks for dates.
Loading

0 comments on commit c93c066

Please sign in to comment.