Repository: sharkdp/bat (language: rust)

Issue:
Gnuplot
<!--
BEFORE YOU MAKE A REQUEST:

Are you looking to add a new syntax to use on one of your devices?
Bat supports locally-installed language definitions. See the link below:

https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions

If you think adding this syntax would help others as well, please make sure that it meets our
guidelines for adding new syntaxes:

 - 10,000 downloads on packagecontrol.io
-->


**Syntax:**
Gnuplot

**Guideline Criteria:**
https://packagecontrol.io/packages/Gnuplot (currently at 7K only)


Discussion / hints:

Fix patch:
diff --git a/.gitmodules b/.gitmodules
index 99364ba641..3dcbc5191f 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -213,3 +213,6 @@
 [submodule "assets/syntaxes/02_Extra/Zig"]
 	path = assets/syntaxes/02_Extra/Zig
 	url = https://github.com/ziglang/sublime-zig-language.git
+[submodule "assets/syntaxes/02_Extra/gnuplot"]
+	path = assets/syntaxes/02_Extra/gnuplot
+	url = https://github.com/hesstobi/sublime_gnuplot
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 5b604aa6cb..fe1f80d4c2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -25,6 +25,7 @@
 - Added Zig syntax, see #1470 (@paulsmith)
 - Added Lean syntax, see #1446 (@Julian)
 - Added `.resource` extension for Robot Framework files, see #1386
+- Added `gnuplot` syntax, see #1431 (@sharkdp)
 
 ## New themes
 
diff --git a/assets/syntaxes/02_Extra/gnuplot b/assets/syntaxes/02_Extra/gnuplot
new file mode 160000
index 0000000000..04743470ff
--- /dev/null
+++ b/assets/syntaxes/02_Extra/gnuplot
@@ -0,0 +1,1 @@
+Subproject commit 04743470ff90237ba3fb34ccf77c2d256d611262
diff --git a/assets/syntaxes/02_Extra/gnuplot.sublime-syntax b/assets/syntaxes/02_Extra/gnuplot.sublime-syntax
new file mode 100644
index 0000000000..65ca562199
--- /dev/null
+++ b/assets/syntaxes/02_Extra/gnuplot.sublime-syntax
@@ -0,0 +1,182 @@
+%YAML 1.2
+---
+# http://www.sublimetext.com/docs/3/syntax.html
+name: gnuplot
+file_extensions:
+  - gp
+  - gpl
+  - gnuplot
+  - gnu
+  - plot
+  - plt
+scope: source.gnuplot
+contexts:
+  main:
+    - include: number
+    - include: string_single
+    - include: string_double
+    - match: '\b(for)\b\s*(\[)'
+      comment: |
+        gnuplot iteration statement.
+                    There are two forms:
+                        numeric [n = 1:2{:inc}]
+                        string based [str in "x y z"]
+                        but both can also iterate over lists etc, so this is kept loose.
+      captures:
+        1: keyword.other.iteration.gnuplot
+        2: punctuation.definition.range.begin.gnuplot
+      push:
+        - meta_scope: meta.structure.iteration.gnuplot
+        - match: '\]'
+          captures:
+            0: punctuation.definition.range.end.gnuplot
+          pop: true
+        - include: number
+        - include: operator
+        - include: string_double
+        - include: string_single
+        - match: ":"
+          scope: punctuation.separator.range.gnuplot
+        - match: '\b([a-zA-Z]\w*)\b\s*(=|in)'
+          scope: variable-assignment.range.gnuplot
+        - match: '(?i:[^\s(pi|e)\]])'
+          scope: invalid.illegal.expected-range-separator.gnuplot
+    - match: '\['
+      comment: "gnuplot range statement [a:b]. Lots of things are legal, still more make no sense!"
+      captures:
+        0: punctuation.definition.range.begin.gnuplot
+      push:
+        - meta_scope: meta.structure.range.gnuplot
+        - match: '\]'
+          captures:
+            0: punctuation.definition.range.end.gnuplot
+          pop: true
+        - include: number
+        - include: operator
+        - match: ":"
+          scope: punctuation.separator.range.gnuplot
+        - match: '(?i:[^\s(pi|e)\]])'
+          scope: invalid.illegal.expected-range-separator.gnuplot
+    - match: \\.
+      scope: constant.character.escape.gnuplot
+    - match: '(?<!\$)(#)(?!\{).*$\n?'
+      scope: comment.line.number-sign.gnuplot
+      captures:
+        1: punctuation.definition.comment.gnuplot
+    - match: for
+      comment: introduce in gnuplot 4.3.
+      scope: keyword.other.iteration.gnuplot
+    - match: \b(angles|arrow|autoscale|bars|border|boxwidth|clabel|clip|cntrparam|colorbox|contour|decimalsign|dgrid3d|dummy|encoding|fit|format|grid|hidden3d|historysize|isosamples|key|label|locale|logscale|macros|bmargin|lmargin|rmargin|tmargin|mapping|mouse|multiplot|offsets|origin|output|palette|parametric|pm3d|pointsize|polar|print|rrange|trange|urange|vrange|samples|size|style|surface|tics|ticscale|ticslevel|timestamp|timefmt|title|view|xyplane|x2data|xdata|y2data|ydata|z2data|zdata|x2label|xlabel|y2label|ylabel|z2label|zlabel|x2range|xrange|y2range|yrange|z2range|zrange|mx2tics|mxtics|my2tics|mytics|mz2tics|mztics|nomx2tics|nomxtics|nomy2tics|nomytics|nomz2tics|nomztics|nox2tics|noxtics|noy2tics|noytics|noz2tics|noztics|x2tics|xtics|y2tics|ytics|z2tics|ztics|x2dtics|x2mtics|xdtics|xmtics|y2dtics|y2mtics|ydtics|ymtics|z2dtics|z2mtics|zdtics|zmtics|x2zeroaxis|xzeroaxis|y2zeroaxis|yzeroaxis|z2zeroaxis|zeroaxis|zzeroaxis|zero|)\b
+      scope: keyword.other.setting.gnuplot
+    - match: \b(cd|call|clear|exit|plot|splot|help|load|pause|quit|fit|replot|if|FIT_LIMIT|FIT_MAXITER|FIT_START_LAMBDA|FIT_LAMBDA_FACTOR|FIT_LOG|FIT_SCRIPT|print|pwd|reread|reset|save|show|test|!|functions|var)\b
+      comment: missuse of scopes alert! Just for pretty colours
+      scope: keyword.other.command.gnuplot
+    - match: \b(abs|acos|acosh|arg|asin|asinh|atan|atan2|atanh|besj0|besj1|besy0|besy1|ceil|cos|cosh|erf|erfc|exp|floor|gamma|ibeta|igamma|imag|int|inverf|invnorm|lambertw|lgamma|log|log10|norm|rand|real|sgn|sin|sinh|sqrt|tan|tanh)\b
+      scope: support.function.gnuplot
+    - match: \b(gprintf|sprintf|strlen|strstrt|substr|system|word|words)\b
+      scope: support.function.string.gnuplot
+    - match: \b(on|off|default|inside|outside|lmargin|rmargin|tmargin|bmargin|at|left|right|center|top|bottom|center|vertical|horizontal|Left|Right|noreverse|noinvert|samplen|spacing|width|height|noautotitle|columnheader|title|noenhanced|nobox|linestyle|ls|linetype|lt|linewidth|lw)\b
+      scope: constant.other.type.gnuplot
+    - match: \b(aed512|aed767|aifm|aqua|bitgraph|cgm|corel|dumb|dxf|eepic|emf|emtex|epslatex|epson_180dpi|epson_60dpi|epson_lx800|fig|gif|gpic|hp2623A|hp2648|hp500c|hpdj|hpgl|hpljii|hppj|imagen|jpeg|kc_tek40xx|km_tek40xx|latex|mf|mif|mp|nec_cp6|okidata|pbm|pcl5|pdf|png|postscript|pslatex|pstex|pstricks|qms|regis|selanar|starc|svg|tandy_60dpi|tek40xx|tek410x|texdraw|tgif|tkcanvas|tpic|unknown|vttek)\b
+      scope: constant.other.terminal.gnuplot
+    - match: \b(u(sing)?|t(it(le)?)?|notit(le)?|w(i(th)?)?|steps|fs(teps)?|notitle|l(i(nes)?)?|linespoints|via)\b
+      scope: keyword.modifier.gnuplot
+    - match: |-
+        (?x:
+          \b # Start with a word boundary
+          (?=\b[\w$]*(\(|.*=))  # Look-ahead for a bracket or equals
+          (?![^(]*\)) # negative look ahead for a closing bracket without an opening one. This stops a from matching in f(a)
+          (         # Group variable name
+            [A-Za-z]      # A letter
+            [\w$]*      # Any word chars or $
+          )         # That is it for the name.
+        )
+      comment: user defined function / variable
+      scope: variable.other.gnuplot
+    - match: \b(if)\b
+      scope: keyword.control.gnuplot
+    - match: \b(show)\b
+      captures:
+        0: keyword.other.command.gnuplot
+      push:
+        - meta_scope: keyword.line.show.gnuplot
+        - meta_content_scope: keyword.line.show.gnuplot
+        - match: (?!\#)($\n?)
+          pop: true
+        - include: main
+    - match: \b(set)\b\s*\b(terminal|term)\b
+      captures:
+        1: keyword.other.command.gnuplot
+        2: keyword.other.setting.gnuplot
+      push:
+        - meta_scope: keyword.line.set.terminal.gnuplot
+        - match: (?!\#)($\n?)
+          pop: true
+        - include: main
+    - match: \b(set)\b\s*\b(key)\b
+      captures:
+        1: keyword.other.command.gnuplot
+        2: keyword.other.setting.gnuplot
+      push:
+        - meta_scope: keyword.line.set.key.gnuplot
+        - match: (?!\#)($\n?)
+          pop: true
+        - include: main
+    - match: \b(set|unset)\b\s*(?!\b(terminal|key|for)\b)
+      captures:
+        1: keyword.other.command.gnuplot
+        2: keyword.other.setting.gnuplot
+      push:
+        - meta_scope: keyword.line.set.gnuplot
+        - meta_content_scope: keyword.line.set.gnuplot
+        - match: (?!\#)($\n?)
+          pop: true
+        - include: main
+  number:
+    - match: |-
+        (?x:         # turn on extended mode
+            -?         # an optional minus
+            (?:
+              0        # a zero
+              |        # ...or...
+              [1-9]    # a 1-9 character
+              \d*      # followed by zero or more digits
+            )
+            (?:
+              \.       # a period
+              \d+      # followed by one or more digits
+              (?:
+                [eE]   # an e character
+                [+-]?  # followed by an option +/-
+                \d+    # followed by one or more digits
+              )?       # make exponent optional
+            )?         # make decimal portion optional
+        )
+      comment: borrowed from textmate book
+      scope: constant.numeric.gnuplot
+  operator:
+    - match: \s*(==|~=|>|>=|<|<=|&|&&|:|\||\|\||\+|-|\*|\.\*|/|\./|\\|\.\\|\^|\.\^)\s*
+      comment: Operator symbols
+      scope: keyword.operator.symbols.matlab
+  string_double:
+    - match: '"'
+      captures:
+        0: punctuation.definition.string.begin.gnuplot
+      push:
+        - meta_scope: string.quoted.double.gnuplot
+        - match: '"'
+          captures:
+            0: punctuation.definition.string.end.gnuplot
+          pop: true
+        - match: '\\[\$`"\\\n]'
+          scope: constant.character.escape.gnuplot
+  string_single:
+    - match: "'"
+      captures:
+        0: punctuation.definition.string.begin.gnuplot
+      push:
+        - meta_scope: string.quoted.single.gnuplot
+        - match: "'"
+          captures:
+            0: punctuation.definition.string.end.gnuplot
+          pop: true


Test patch:
diff --git a/tests/syntax-tests/highlighted/gnuplot/test.gp b/tests/syntax-tests/highlighted/gnuplot/test.gp
new file mode 100644
index 0000000000..bb96f60d7d
--- /dev/null
+++ b/tests/syntax-tests/highlighted/gnuplot/test.gp
@@ -0,0 +1,19 @@
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114mterminal[0m[38;2;249;38;114m pngcairo enhanced[0m
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114moutput[0m[38;2;249;38;114m [0m[38;2;230;219;116m"[0m[38;2;230;219;116m/tmp/polynomial.png[0m[38;2;230;219;116m"[0m
+
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114mgrid[0m
+
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114mxrange[0m[38;2;249;38;114m [0m[38;2;249;38;114m[[0m[38;2;190;132;255m-5[0m[38;2;249;38;114m:[0m[38;2;190;132;255m5[0m[38;2;249;38;114m][0m
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114myrange[0m[38;2;249;38;114m [0m[38;2;249;38;114m[[0m[38;2;190;132;255m-5[0m[38;2;249;38;114m:[0m[38;2;190;132;255m10[0m[38;2;249;38;114m][0m
+
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114msamples[0m[38;2;249;38;114m [0m[38;2;190;132;255m10000[0m
+
+[38;2;249;38;114mset[0m[38;2;249;38;114m [0m[38;2;249;38;114mkey[0m[38;2;249;38;114m [0m[38;2;190;132;255mbottom[0m[38;2;249;38;114m [0m[38;2;190;132;255mright[0m
+
+[38;2;255;255;255mf[0m[38;2;248;248;242m(x) = [0m[38;2;190;132;255m1.0[0m[38;2;248;248;242m / [0m[38;2;190;132;255m14.0[0m[38;2;248;248;242m * ((x+[0m[38;2;190;132;255m4[0m[38;2;248;248;242m) * (x+[0m[38;2;190;132;255m1[0m[38;2;248;248;242m) * (x[0m[38;2;190;132;255m-1[0m[38;2;248;248;242m) * (x[0m[38;2;190;132;255m-3[0m[38;2;248;248;242m)) + [0m[38;2;190;132;255m0.5[0m
+
+[38;2;249;38;114mplot[0m[38;2;248;248;242m \[0m
+[38;2;248;248;242m    [0m[38;2;255;255;255mf[0m[38;2;248;248;242m(x) [0m[38;2;190;132;255mtitle[0m[38;2;248;248;242m [0m[38;2;230;219;116m"[0m[38;2;230;219;116mpolynomial of degree 4[0m[38;2;230;219;116m"[0m[38;2;248;248;242m \[0m
+[38;2;248;248;242m    [0m[38;2;249;38;114mwith[0m[38;2;248;248;242m [0m[38;2;249;38;114mlines[0m[38;2;248;248;242m \[0m
+[38;2;248;248;242m    [0m[38;2;190;132;255mlinewidth[0m[38;2;248;248;242m [0m[38;2;190;132;255m2[0m[38;2;248;248;242m \[0m
+[38;2;248;248;242m    [0m[38;2;190;132;255mlinetype[0m[38;2;248;248;242m rgb [0m[38;2;230;219;116m'[0m[38;2;230;219;116m#0077ff[0m[38;2;230;219;116m'[0m
diff --git a/tests/syntax-tests/source/gnuplot/test.gp b/tests/syntax-tests/source/gnuplot/test.gp
new file mode 100644
index 0000000000..411cf134b5
--- /dev/null
+++ b/tests/syntax-tests/source/gnuplot/test.gp
@@ -0,0 +1,19 @@
+set terminal pngcairo enhanced
+set output "/tmp/polynomial.png"
+
+set grid
+
+set xrange [-5:5]
+set yrange [-5:10]
+
+set samples 10000
+
+set key bottom right
+
+f(x) = 1.0 / 14.0 * ((x+4) * (x+1) * (x-1) * (x-3)) + 0.5
+
+plot \
+    f(x) title "polynomial of degree 4" \
+    with lines \
+    linewidth 2 \
+    linetype rgb '#0077ff'