Skip to content

Commit 2288c25

Browse files
RunDevelopmentmAAdhaTTah
authored andcommitted
Add G-code language (#1572)
This PR adds the [G-code language](https://reprap.org/wiki/G-code) to Prism and resolves #1571. ### Features - All fields from A-Z ([case sensitive](https://reprap.org/wiki/G-code#Case_sensitivity)) and [checksums](https://reprap.org/wiki/G-code#.2A:_Checksum) (`*`). - [Comments](https://reprap.org/wiki/G-code#Comments) of both the semicolon and parenthesis style. - [Quoted strings](https://reprap.org/wiki/G-code#Quoted_strings). - The colon punctuation of [lists (see the example)](https://reprap.org/wiki/G-code#M584:_Set_drive_mapping).
1 parent 225dd3f commit 2288c25

12 files changed

+134
-3
lines changed

components.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

components.json

+4
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,10 @@
266266
"title": "Fortran",
267267
"owner": "Golmote"
268268
},
269+
"gcode": {
270+
"title": "G-code",
271+
"owner": "RunDevelopment"
272+
},
269273
"gedcom": {
270274
"title": "GEDCOM",
271275
"owner": "Golmote"

components/prism-gcode.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Prism.languages.gcode = {
2+
'comment': /;.*|\B\(.*?\)\B/,
3+
'string': {
4+
pattern: /"(?:""|[^"])*"/,
5+
greedy: true
6+
},
7+
'keyword': /\b[GM]\d+(?:\.\d+)?\b/,
8+
'property': /\b[A-Z]/,
9+
'checksum': {
10+
pattern: /\*\d+/,
11+
alias: 'punctuation'
12+
},
13+
// T0:0:0
14+
'punctuation': /:/
15+
};

components/prism-gcode.min.js

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/prism-gcode.html

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<h2>Comments</h2>
2+
<pre><code>; comment
3+
(some more comments)
4+
G28 (even in here) X0
5+
</code></pre>
6+
7+
<h2>Quoted strings</h2>
8+
<pre><code>"foo""bar"</code></pre>
9+
10+
<h2>Full example</h2>
11+
<pre><code>M190 S60 ; Heat bed to 60°C
12+
G21 ; Set units to millimeters
13+
G28 ; Move to Origin (Homing)
14+
G29 ; Auto Bed Leveling
15+
G28 X0 Y0 ; Home X and Y to min endstops
16+
M107 ; Fan off
17+
M109 S200 ; Heat hotend to 200°C
18+
G92 E0 ; Set current extruder position as zero
19+
G1 F200 E15 ; Extrude 15mm filament with 200mm/min
20+
G92 E0 ; Set current extruder position as zero
21+
G1 F500
22+
</code></pre>

plugins/show-language/prism-show-language.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ if (!Prism.plugins.toolbar) {
1111
}
1212

1313
// The languages map is built automatically with gulp
14-
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
14+
var Languages = /*languages_placeholder[*/{"html":"HTML","xml":"XML","svg":"SVG","mathml":"MathML","css":"CSS","clike":"C-like","javascript":"JavaScript","abap":"ABAP","actionscript":"ActionScript","apacheconf":"Apache Configuration","apl":"APL","applescript":"AppleScript","arff":"ARFF","asciidoc":"AsciiDoc","asm6502":"6502 Assembly","aspnet":"ASP.NET (C#)","autohotkey":"AutoHotkey","autoit":"AutoIt","shell":"Shell","basic":"BASIC","csharp":"C#","cpp":"C++","cil":"CIL","coffeescript":"CoffeeScript","csp":"Content-Security-Policy","css-extras":"CSS Extras","django":"Django/Jinja2","erb":"ERB","fsharp":"F#","gcode":"G-code","gedcom":"GEDCOM","glsl":"GLSL","gml":"GameMaker Language","graphql":"GraphQL","http":"HTTP","hpkp":"HTTP Public-Key-Pins","hsts":"HTTP Strict-Transport-Security","ichigojam":"IchigoJam","inform7":"Inform 7","json":"JSON","jsonp":"JSONP","latex":"LaTeX","livescript":"LiveScript","lolcode":"LOLCODE","markup-templating":"Markup templating","matlab":"MATLAB","mel":"MEL","n4js":"N4JS","nasm":"NASM","nginx":"nginx","nsis":"NSIS","objectivec":"Objective-C","ocaml":"OCaml","opencl":"OpenCL","parigp":"PARI/GP","objectpascal":"Object Pascal","php":"PHP","php-extras":"PHP Extras","plsql":"PL/SQL","powershell":"PowerShell","properties":".properties","protobuf":"Protocol Buffers","q":"Q (kdb+ database)","jsx":"React JSX","tsx":"React TSX","renpy":"Ren'py","rest":"reST (reStructuredText)","sas":"SAS","sass":"Sass (Sass)","scss":"Sass (Scss)","sql":"SQL","soy":"Soy (Closure Template)","tap":"TAP","tt2":"Template Toolkit 2","typescript":"TypeScript","vbnet":"VB.Net","vhdl":"VHDL","vim":"vim","visual-basic":"Visual Basic","wasm":"WebAssembly","wiki":"Wiki markup","xeoracube":"XeoraCube","xojo":"Xojo (REALbasic)","xquery":"XQuery","yaml":"YAML"}/*]*/;
1515
Prism.plugins.toolbar.registerButton('show-language', function(env) {
1616
var pre = env.element.parentNode;
1717
if (!pre || !/pre/i.test(pre.nodeName)) {

plugins/show-language/prism-show-language.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
G28*22
2+
3+
----------------------------------------------------
4+
5+
[
6+
["keyword", "G28"],
7+
["checksum", "*22"]
8+
]
9+
10+
----------------------------------------------------
11+
12+
Checks for checksums.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
; foo
2+
(Home some axes)
3+
G28 (here come the axes to be homed) X
4+
5+
----------------------------------------------------
6+
7+
[
8+
["comment", "; foo"],
9+
10+
["comment", "(Home some axes)"],
11+
12+
["keyword", "G28"],
13+
["comment", "(here come the axes to be homed)"],
14+
["property", "X"]
15+
16+
]
17+
18+
----------------------------------------------------
19+
20+
Checks for comments.
+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
G00
2+
G200
3+
G84.1
4+
5+
M00
6+
M123
7+
M52.4
8+
9+
----------------------------------------------------
10+
11+
[
12+
["keyword", "G00"],
13+
["keyword", "G200"],
14+
["keyword", "G84.1"],
15+
16+
["keyword", "M00"],
17+
["keyword", "M123"],
18+
["keyword", "M52.4"]
19+
]
20+
21+
----------------------------------------------------
22+
23+
Checks for G- and M-codes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
X123
2+
Y0.2
3+
Z-3.1415
4+
E420:420
5+
6+
----------------------------------------------------
7+
8+
[
9+
["property", "X"], "123\n",
10+
["property", "Y"], "0.2\n",
11+
["property", "Z"], "-3.1415\n",
12+
["property", "E"], "420", ["punctuation", ":"], "420"
13+
]
14+
15+
----------------------------------------------------
16+
17+
Checks for all other codes except G- and M-codes.
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
M587 S"MYROUTER" P"ABCxyz;"" 123"
2+
3+
----------------------------------------------------
4+
5+
[
6+
["keyword", "M587"],
7+
8+
["property", "S"],
9+
["string", "\"MYROUTER\""],
10+
11+
["property", "P"],
12+
["string", "\"ABCxyz;\"\" 123\""]
13+
]
14+
15+
----------------------------------------------------
16+
17+
Checks for strings.

0 commit comments

Comments
 (0)