Skip to content

Commit 83f6843

Browse files
authored
Merge branch 'main' into cybertopia
2 parents c5d4cd2 + 7893353 commit 83f6843

File tree

14 files changed

+937
-131
lines changed

14 files changed

+937
-131
lines changed

CHANGES.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,28 @@ Core Grammars:
1717
- enh(csharp) add Contextual keywords `file`, `args`, `dynamic`, `record`, `required` and `scoped` [Alvin Joy][]
1818
- enh(lua) add 'pluto' as an alias [Sainan]
1919
- enh(bash) add reserved keywords `time` and `coproc` [Álvaro Mondéjar][]
20+
- enh(nix) update keywords [h7x4][]
21+
- enh(nix) support paths [h7x4][]
22+
- enh(nix) support lookup paths [h7x4][]
23+
- enh(nix) support operators [h7x4][]
24+
- enh(nix) support REPL keywords [h7x4][]
25+
- enh(nix) support markdown comments [h7x4][]
26+
- enh(nix) support basic function params [h7x4][]
27+
- enh(nix) better parsing of attrsets [h7x4][]
2028
- fix(c) - Fixed hex numbers with decimals [Dxuian]
2129
- fix(typescript) - Fixedoptional property not highlighted correctly [Dxuian]
2230
- fix(ruby) - fix `|=` operator false positives (as block arguments) [Aboobacker MK]
31+
- enh(gcode) rewrote language for modern gcode support [Barthélémy Bonhomme][]
2332
- fix(sql) - Fixed sql primary key and foreign key spacing issue [Dxuian]
2433
- fix(cpp) added flat_set and flat_map as a part of cpp 23 version [Lavan]
2534
- fix(yaml) - Fixed special chars in yaml [Dxuian]
2635
- fix(basic) - Fixed closing quotation marks not required for a PRINT statement [Somya]
36+
- fix(nix) remove `add` builtin [h7x4][]
37+
- fix(nix) mark `or` as builtin instead of literal [h7x4][]
38+
- fix(nix) handle `'''` string escapes [h7x4][]
39+
- fix(nix) handle backslash string escapes [h7x4][]
40+
- fix(nix) don't mix escapes for `"` and `''` strings [h7x4][]
41+
- fix(swift) - Fixed syntax highlighting for class func/var declarations [guuido]
2742

2843
New Grammars:
2944

@@ -61,8 +76,10 @@ CONTRIBUTORS
6176
[Osmocom]: https://github.com/osmocom
6277
[Álvaro Mondéjar]: https://github.com/mondeja
6378
[Alexandre ZANNI]: https://github.com/noraj
79+
[Barthélémy Bonhomme]: https://github.com/barthy-koeln
6480
[Lavan]: https://github.com/jvlavan
6581
[Somya]: https://github.com/somya-05
82+
[guuido]: https://github.com/guuido
6683

6784

6885
## Version 11.10.0
@@ -174,7 +191,6 @@ Themes:
174191
[Chiel van de Steeg]: https://github.com/cvdsteeg
175192

176193

177-
178194
## Version 11.9.0
179195

180196
CAVEATS / POTENTIALLY BREAKING CHANGES

src/languages/gcode.js

Lines changed: 149 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,58 +7,170 @@
77
*/
88

99
export default function(hljs) {
10-
const GCODE_IDENT_RE = '[A-Z_][A-Z0-9_.]*';
11-
const GCODE_CLOSE_RE = '%';
10+
const regex = hljs.regex;
1211
const GCODE_KEYWORDS = {
13-
$pattern: GCODE_IDENT_RE,
14-
keyword: 'IF DO WHILE ENDWHILE CALL ENDIF SUB ENDSUB GOTO REPEAT ENDREPEAT '
15-
+ 'EQ LT GT NE GE LE OR XOR'
16-
};
17-
const GCODE_START = {
18-
className: 'meta',
19-
begin: '([O])([0-9]+)'
12+
$pattern: /[A-Z]+|%/,
13+
keyword: [
14+
// conditions
15+
'THEN',
16+
'ELSE',
17+
'ENDIF',
18+
'IF',
19+
20+
// controls
21+
'GOTO',
22+
'DO',
23+
'WHILE',
24+
'WH',
25+
'END',
26+
'CALL',
27+
28+
// scoping
29+
'SUB',
30+
'ENDSUB',
31+
32+
// comparisons
33+
'EQ',
34+
'NE',
35+
'LT',
36+
'GT',
37+
'LE',
38+
'GE',
39+
'AND',
40+
'OR',
41+
'XOR',
42+
43+
// start/end of program
44+
'%'
45+
],
46+
built_in: [
47+
'ATAN',
48+
'ABS',
49+
'ACOS',
50+
'ASIN',
51+
'COS',
52+
'EXP',
53+
'FIX',
54+
'FUP',
55+
'ROUND',
56+
'LN',
57+
'SIN',
58+
'SQRT',
59+
'TAN',
60+
'EXISTS'
61+
]
2062
};
21-
const NUMBER = hljs.inherit(hljs.C_NUMBER_MODE, { begin: '([-+]?((\\.\\d+)|(\\d+)(\\.\\d*)?))|' + hljs.C_NUMBER_RE });
63+
64+
65+
// TODO: post v12 lets use look-behind, until then \b and a callback filter will be used
66+
// const LETTER_BOUNDARY_RE = /(?<![A-Z])/;
67+
const LETTER_BOUNDARY_RE = /\b/;
68+
69+
function LETTER_BOUNDARY_CALLBACK(matchdata, response) {
70+
if (matchdata.index === 0) {
71+
return;
72+
}
73+
74+
const charBeforeMatch = matchdata.input[matchdata.index - 1];
75+
if (charBeforeMatch >= '0' && charBeforeMatch <= '9') {
76+
return;
77+
}
78+
79+
if (charBeforeMatch === '_') {
80+
return;
81+
}
82+
83+
response.ignoreMatch();
84+
}
85+
86+
const NUMBER_RE = /[+-]?((\.\d+)|(\d+)(\.\d*)?)/;
87+
88+
const GENERAL_MISC_FUNCTION_RE = /[GM]\s*\d+(\.\d+)?/;
89+
const TOOLS_RE = /T\s*\d+/;
90+
const SUBROUTINE_RE = /O\s*\d+/;
91+
const SUBROUTINE_NAMED_RE = /O<.+>/;
92+
const AXES_RE = /[ABCUVWXYZ]\s*/;
93+
const PARAMETERS_RE = /[FHIJKPQRS]\s*/;
94+
2295
const GCODE_CODE = [
23-
hljs.C_LINE_COMMENT_MODE,
24-
hljs.C_BLOCK_COMMENT_MODE,
96+
// comments
2597
hljs.COMMENT(/\(/, /\)/),
26-
NUMBER,
27-
hljs.inherit(hljs.APOS_STRING_MODE, { illegal: null }),
28-
hljs.inherit(hljs.QUOTE_STRING_MODE, { illegal: null }),
98+
hljs.COMMENT(/;/, /$/),
99+
hljs.APOS_STRING_MODE,
100+
hljs.QUOTE_STRING_MODE,
101+
hljs.C_NUMBER_MODE,
102+
103+
// gcodes
29104
{
30-
className: 'name',
31-
begin: '([G])([0-9]+\\.?[0-9]?)'
105+
scope: 'title.function',
106+
variants: [
107+
// G General functions: G0, G5.1, G5.2, …
108+
// M Misc functions: M0, M55.6, M199, …
109+
{ match: regex.concat(LETTER_BOUNDARY_RE, GENERAL_MISC_FUNCTION_RE) },
110+
{
111+
begin: GENERAL_MISC_FUNCTION_RE,
112+
'on:begin': LETTER_BOUNDARY_CALLBACK
113+
},
114+
// T Tools
115+
{ match: regex.concat(LETTER_BOUNDARY_RE, TOOLS_RE), },
116+
{
117+
begin: TOOLS_RE,
118+
'on:begin': LETTER_BOUNDARY_CALLBACK
119+
}
120+
]
32121
},
122+
33123
{
34-
className: 'name',
35-
begin: '([M])([0-9]+\\.?[0-9]?)'
124+
scope: 'symbol',
125+
variants: [
126+
// O Subroutine ID: O100, O110, …
127+
{ match: regex.concat(LETTER_BOUNDARY_RE, SUBROUTINE_RE) },
128+
{
129+
begin: SUBROUTINE_RE,
130+
'on:begin': LETTER_BOUNDARY_CALLBACK
131+
},
132+
// O Subroutine name: O<some>, …
133+
{ match: regex.concat(LETTER_BOUNDARY_RE, SUBROUTINE_NAMED_RE) },
134+
{
135+
begin: SUBROUTINE_NAMED_RE,
136+
'on:begin': LETTER_BOUNDARY_CALLBACK
137+
},
138+
// Checksum at end of line: *71, *199, …
139+
{ match: /\*\s*\d+\s*$/ }
140+
]
36141
},
142+
37143
{
38-
className: 'attr',
39-
begin: '(VC|VS|#)',
40-
end: '(\\d+)'
144+
scope: 'operator', // N Line number: N1, N2, N1020, …
145+
match: /^N\s*\d+/
41146
},
147+
42148
{
43-
className: 'attr',
44-
begin: '(VZOFX|VZOFY|VZOFZ)'
149+
scope: 'variable',
150+
match: /-?#\s*\d+/
45151
},
152+
46153
{
47-
className: 'built_in',
48-
begin: '(ATAN|ABS|ACOS|ASIN|SIN|COS|EXP|FIX|FUP|ROUND|LN|TAN)(\\[)',
49-
contains: [ NUMBER ],
50-
end: '\\]'
154+
scope: 'property', // Physical axes,
155+
variants: [
156+
{ match: regex.concat(LETTER_BOUNDARY_RE, AXES_RE, NUMBER_RE) },
157+
{
158+
begin: regex.concat(AXES_RE, NUMBER_RE),
159+
'on:begin': LETTER_BOUNDARY_CALLBACK
160+
},
161+
]
51162
},
163+
52164
{
53-
className: 'symbol',
165+
scope: 'params', // Different types of parameters
54166
variants: [
167+
{ match: regex.concat(LETTER_BOUNDARY_RE, PARAMETERS_RE, NUMBER_RE) },
55168
{
56-
begin: 'N',
57-
end: '\\d+',
58-
illegal: '\\W'
59-
}
169+
begin: regex.concat(PARAMETERS_RE, NUMBER_RE),
170+
'on:begin': LETTER_BOUNDARY_CALLBACK
171+
},
60172
]
61-
}
173+
},
62174
];
63175

64176
return {
@@ -67,13 +179,9 @@ export default function(hljs) {
67179
// Some implementations (CNC controls) of G-code are interoperable with uppercase and lowercase letters seamlessly.
68180
// However, most prefer all uppercase and uppercase is customary.
69181
case_insensitive: true,
182+
// TODO: post v12 with the use of look-behind this can be enabled
183+
disableAutodetect: true,
70184
keywords: GCODE_KEYWORDS,
71-
contains: [
72-
{
73-
className: 'meta',
74-
begin: GCODE_CLOSE_RE
75-
},
76-
GCODE_START
77-
].concat(GCODE_CODE)
185+
contains: GCODE_CODE
78186
};
79187
}

0 commit comments

Comments
 (0)