]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/gcode.js
1 /*! `gcode` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
6 Language: G-code (ISO 6983)
7 Contributors: Adam Joseph Cook <adam.joseph.cook@gmail.com>
8 Description: G-code syntax highlighter for Fanuc and other common CNC machine tool controls.
9 Website: https://www.sis.se/api/document/preview/911952/
13 function gcode(hljs
) {
14 const regex
= hljs
.regex
;
15 const GCODE_KEYWORDS
= {
47 // start/end of program
69 // TODO: post v12 lets use look-behind, until then \b and a callback filter will be used
70 // const LETTER_BOUNDARY_RE = /(?<![A-Z])/;
71 const LETTER_BOUNDARY_RE
= /\b/;
73 function LETTER_BOUNDARY_CALLBACK(matchdata
, response
) {
74 if (matchdata
.index
=== 0) {
78 const charBeforeMatch
= matchdata
.input
[matchdata
.index
- 1];
79 if (charBeforeMatch
>= '0' && charBeforeMatch
<= '9') {
83 if (charBeforeMatch
=== '_') {
87 response
.ignoreMatch();
90 const NUMBER_RE
= /[+-]?((\.\d+)|(\d+)(\.\d*)?)/;
92 const GENERAL_MISC_FUNCTION_RE
= /[GM]\s*\d+(\.\d+)?/;
93 const TOOLS_RE
= /T\s*\d+/;
94 const SUBROUTINE_RE
= /O\s*\d+/;
95 const SUBROUTINE_NAMED_RE
= /O<.+>/;
96 const AXES_RE
= /[ABCUVWXYZ]\s*/;
97 const PARAMETERS_RE
= /[FHIJKPQRS]\s*/;
101 hljs
.COMMENT(/\(/, /\)/),
102 hljs
.COMMENT(/;/, /$/),
103 hljs
.APOS_STRING_MODE
,
104 hljs
.QUOTE_STRING_MODE
,
109 scope: 'title.function',
111 // G General functions: G0, G5.1, G5.2, …
112 // M Misc functions: M0, M55.6, M199, …
113 { match: regex
.concat(LETTER_BOUNDARY_RE
, GENERAL_MISC_FUNCTION_RE
) },
115 begin: GENERAL_MISC_FUNCTION_RE
,
116 'on:begin': LETTER_BOUNDARY_CALLBACK
119 { match: regex
.concat(LETTER_BOUNDARY_RE
, TOOLS_RE
), },
122 'on:begin': LETTER_BOUNDARY_CALLBACK
130 // O Subroutine ID: O100, O110, …
131 { match: regex
.concat(LETTER_BOUNDARY_RE
, SUBROUTINE_RE
) },
133 begin: SUBROUTINE_RE
,
134 'on:begin': LETTER_BOUNDARY_CALLBACK
136 // O Subroutine name: O<some>, …
137 { match: regex
.concat(LETTER_BOUNDARY_RE
, SUBROUTINE_NAMED_RE
) },
139 begin: SUBROUTINE_NAMED_RE
,
140 'on:begin': LETTER_BOUNDARY_CALLBACK
142 // Checksum at end of line: *71, *199, …
143 { match: /\*\s*\d+\s*$/ }
148 scope: 'operator', // N Line number: N1, N2, N1020, …
158 scope: 'property', // Physical axes,
160 { match: regex
.concat(LETTER_BOUNDARY_RE
, AXES_RE
, NUMBER_RE
) },
162 begin: regex
.concat(AXES_RE
, NUMBER_RE
),
163 'on:begin': LETTER_BOUNDARY_CALLBACK
169 scope: 'params', // Different types of parameters
171 { match: regex
.concat(LETTER_BOUNDARY_RE
, PARAMETERS_RE
, NUMBER_RE
) },
173 begin: regex
.concat(PARAMETERS_RE
, NUMBER_RE
),
174 'on:begin': LETTER_BOUNDARY_CALLBACK
181 name: 'G-code (ISO 6983)',
183 // Some implementations (CNC controls) of G-code are interoperable with uppercase and lowercase letters seamlessly.
184 // However, most prefer all uppercase and uppercase is customary.
185 case_insensitive: true,
186 // TODO: post v12 with the use of look-behind this can be enabled
187 disableAutodetect: true,
188 keywords: GCODE_KEYWORDS
,
197 export default hljsGrammar
;