Skip to content

Commit 454a917

Browse files
authored
Improved highlighting for keywords and macro syntax (#33)
* Allow optional spaces after certain keywords * Give syntax precedence to brackets/keywords/operators This allows certain macro expressions to highlight correctly without being overriden by more generic syntax.
1 parent c5b912c commit 454a917

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

samplenc/sample-colors.nc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,20 @@ G04 P500
9999

100100
IF[#898EQ#996]GOTO19999
101101

102+
IF [123 LE ABS[#452 + 1234]] THEN
103+
(SOMETHING)
104+
ELSE
105+
(SOMETHING ELSE)
106+
ENDIF
107+
108+
WHILE [#123 LT 7.5] DO 5
109+
(SOMETHING HERE)
110+
END 5
111+
112+
WHILE [#123 LT 7.5] DO5
113+
(SOMETHING HERE)
114+
END5
115+
102116
#[#8 + 7.]=0
103117

104118
G51 P[ #5 * 1000 ]

syntaxes/gcode.tmLanguage.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,31 @@
1313
"include": "#comments"
1414
},
1515
{
16-
"include": "#speedsfeeds"
16+
"include": "#bracket-expression"
1717
},
1818
{
19-
"include": "#prognumbers"
19+
"include": "#keywords"
2020
},
2121
{
22-
"include": "#coords"
22+
"include": "#operators"
2323
},
2424
{
25-
"include": "#tools"
25+
"include": "#speedsfeeds"
2626
},
2727
{
28-
"include": "#modifiers"
28+
"include": "#prognumbers"
2929
},
3030
{
31-
"include": "#macrovars"
31+
"include": "#coords"
3232
},
3333
{
34-
"include": "#keywords"
34+
"include": "#tools"
3535
},
3636
{
37-
"include": "#operators"
37+
"include": "#modifiers"
3838
},
3939
{
40-
"include": "#bracket-expression"
40+
"include": "#macrovars"
4141
}
4242
]
4343
},
@@ -57,7 +57,7 @@
5757
"keywords": {
5858
"patterns": [
5959
{
60-
"match": "(GOTO(?>\\d+))|(IF)|(EQ)|(NE)|(LT)|(GT)|(LE)|(GE)|(DO(?>\\d+))|(WHILE)|(WH)|(END(?>\\d+))|(AND)|(OR)|(XOR)",
60+
"match": "(GOTO(?>\\d+))|(IF)|(EQ)|(NE)|(LT)|(GT)|(LE)|(GE)|(DO ?(?>\\d+))|(WHILE)|(WH)|(END ?(?>\\d+))|(AND)|(OR)|(XOR)|(THEN)|(ELSE)|(ENDIF)",
6161
"name": "keyword.control.gcode"
6262
},
6363
{
@@ -219,4 +219,4 @@
219219
]
220220
}
221221
}
222-
}
222+
}

0 commit comments

Comments
 (0)