Browse Source

Update G-code syntax for Sublime

Scott Lahteine 5 years ago
parent
commit
c041eec699

+ 76
- 22
buildroot/share/sublime/RepRapTools/G-Code.sublime-syntax View File

@@ -10,10 +10,10 @@
10 10
 #
11 11
 name: G-Code (RepRap)
12 12
 file_extensions:
13
-  - [ gco, gcode ]
13
+  - [ g, gco, gcode ]
14 14
 scope: source.gcode
15 15
 variables:
16
-  decimal:  '[+-]?\d+(\.(\d+)?)?'
16
+  decimal: '[+-]?\d+(\.\d*)?'
17 17
 
18 18
 contexts:
19 19
   prototype:
@@ -25,11 +25,11 @@ contexts:
25 25
       pop: true
26 26
 
27 27
   main:
28
-    - meta_content_scope: ctx.line.gcode
28
+    - meta_scope: line.gcode
29 29
 
30 30
     - match: '([Nn]\s*(\d+))'
31 31
       captures:
32
-        1: ctx.gcode_line_num
32
+        1: entity.nword.gcode
33 33
         2: constant.numeric.line-number.gcode
34 34
 
35 35
     - match: ()
@@ -40,7 +40,7 @@ contexts:
40 40
     - meta_content_scope: ctx.command.gcode
41 41
 
42 42
     # M20 S2 P/path/to/file/name.gco
43
-    - match: ([Mm](20))(\s*(S)(2)\s*(P))
43
+    - match: ([Mm](20))\s*((S)(2)\s*(P))
44 44
       captures:
45 45
         1: entity.command.gcode markup.bold.gcode
46 46
         2: constant.numeric.command.gcode
@@ -50,15 +50,15 @@ contexts:
50 50
         6: keyword.param.gcode
51 51
       set: gcode_string_arg
52 52
 
53
-    # command followed by data
53
+    # M117 or M118 - Commands taking a string
54 54
     - match: ([Mm]\s*(11[78]))\b
55 55
       captures:
56 56
         1: entity.command.gcode markup.bold.gcode
57 57
         2: constant.numeric.command.gcode
58 58
       set: gcode_string_arg
59 59
 
60
-    # command followed by data
61
-    - match: '([GMTgmt]\s*(\d+)((\.)(\d+))?)'
60
+    # Other commands, followed by data
61
+    - match: ([GMTgmt]\s*(\d+)((\.)(\d+))?)
62 62
       captures:
63 63
         1: entity.command.gcode markup.bold.gcode
64 64
         2: constant.numeric.command.gcode
@@ -74,16 +74,30 @@ contexts:
74 74
     - meta_content_scope: ctx.params.gcode
75 75
 
76 76
     # M32 [S<pos>] [P<bool>] !/path/file.gco#
77
-    - match: '!'
78
-      scope: entity.string.filename.open
77
+    - match: \!
78
+      scope: punctuation.string.path.open.gcode
79 79
       push: gcode_path_arg
80 80
 
81 81
     # asterisk starts a checksum
82 82
     - match: \*
83
-      scope: entity.checksum.gcode
83
+      scope: punctuation.marker.checksum.gcode
84 84
       set: gcode_checksum
85 85
 
86
-    # parameter and value
86
+    # parameter and single-quoted value
87
+    - match: ([A-Za-z])\s*(')
88
+      captures:
89
+        1: keyword.param.gcode
90
+        2: punctuation.quote.single.open.gcode
91
+      push: gcode_string_arg_quoted_single
92
+
93
+    # parameter and double-quoted value
94
+    - match: ([A-Za-z])\s*(")
95
+      captures:
96
+        1: keyword.param.gcode
97
+        2: punctuation.quote.double.open.gcode
98
+      push: gcode_string_arg_quoted_double
99
+
100
+    # parameter and numeric value
87 101
     - match: ([A-Za-z])\s*({{decimal}})
88 102
       captures:
89 103
         1: keyword.param.gcode
@@ -97,27 +111,67 @@ contexts:
97 111
     - match: ()
98 112
       set: syntax_error
99 113
 
114
+  gcode_string_arg_quoted_single:
115
+    - meta_content_scope: string.quoted.single.gcode
116
+
117
+    - match: ([^'\\]+)
118
+
119
+    - match: (\\)
120
+      scope: punctuation.string.escape.gcode
121
+      push: escape_char
122
+
123
+    - match: (')
124
+      scope: punctuation.quote.single.close.gcode
125
+      pop: true
126
+
127
+    - match: ()
128
+      set: syntax_error
129
+
130
+  gcode_string_arg_quoted_double:
131
+    - meta_content_scope: string.quoted.double.gcode
132
+
133
+    - match: ([^"\\]+)
134
+
135
+    - match: (\\)
136
+      scope: punctuation.string.escape.gcode
137
+      push: escape_char
138
+
139
+    - match: (")
140
+      scope: punctuation.quote.double.close.gcode
141
+      pop: true
142
+
143
+    - match: ()
144
+      set: syntax_error
145
+
100 146
   gcode_string_arg:
101 147
     - meta_content_scope: ctx.string.gcode
102 148
 
103 149
     - match: ([^;]+)
104 150
       scope: string.unquoted.gcode
105 151
 
106
-  gcode_path_arg:
107
-    - meta_content_scope: ctx.path.gcode
152
+  escape_char:
153
+    - meta_scope: string.escape.gcode punctuation.string.escape.gcode
108 154
 
109
-    - match: ([^#]+)
110
-      scope: string.unquoted.path.gcode
155
+    - match: '.'
156
+      pop: true
157
+
158
+  gcode_path_arg:
159
+    - meta_content_scope: string.unquoted.path.gcode
111 160
 
112 161
     - match: (#)
113
-      scope: entity.string.path.close.gcode
162
+      scope: punctuation.string.path.close.gcode
114 163
       pop: true
115 164
 
116 165
   gcode_checksum:
117
-    - meta_content_scope: ctx.checksum.gcode
166
+    - meta_content_scope: constant.numeric.checksum.gcode
167
+    - meta_include_prototype: false
118 168
 
119 169
     - match: \d+
120
-      scope: constant.numeric.checksum.gcode
170
+
171
+    - match: ( *)$
172
+      pop: true
173
+
174
+    - include: mixin_comment
121 175
 
122 176
     - match: ()
123 177
       set: syntax_error
@@ -130,15 +184,15 @@ contexts:
130 184
   # Comments begin with a ';' and finish at the end of the line.
131 185
   mixin_comment:
132 186
     - match: ^\s*;
133
-      scope: punctuation.definition.comment.line.start
187
+      scope: punctuation.comment.line.start
134 188
       set: gcode_comment
135 189
     - match: \s*;
136
-      scope: punctuation.definition.comment.eol.start
190
+      scope: punctuation.comment.eol.start
137 191
       set: gcode_comment
138 192
 
139 193
   # Comment to end of line.
140 194
   gcode_comment:
141
-    - meta_scope: comment.gcode
195
+    - meta_content_scope: comment.gcode
142 196
     - match: \s*$
143 197
       pop: true
144 198
 

+ 88
- 0
buildroot/share/sublime/RepRapTools/syntax_test_G-code.gcode View File

@@ -0,0 +1,88 @@
1
+; SYNTAX TEST "G-code.sublime-syntax"
2
+
3
+; This is a G-code comment
4
+;^comment
5
+
6
+G1 X100 Y100 ; Move to 100,100
7
+;^entity.command.gcode
8
+;  ^keyword.param.gcode
9
+;   ^constant.numeric.param.gcode
10
+;              ^comment
11
+
12
+M20 P'/path/to/macro/macro.g' R12
13
+;<-entity.command.gcode
14
+;^constant.numeric.command.gcode
15
+;   ^keyword.param.gcode
16
+;    ^punctuation.quote.single.open.gcode
17
+;       ^string.quoted.single.gcode
18
+;                           ^punctuation.quote.single.close.gcode
19
+
20
+M117 This is a message   ; and comment
21
+;<-entity.command.gcode
22
+;^constant.numeric.command.gcode
23
+;    ^string.unquoted.gcode
24
+;                        ^punctuation.comment.eol.start
25
+;                          ^comment.gcode
26
+
27
+M118 This is a message   ; and comment
28
+;<-entity.command.gcode
29
+;^constant.numeric.command.gcode
30
+;    ^string.unquoted.gcode
31
+;                        ^punctuation.comment.eol.start
32
+;                          ^comment.gcode
33
+
34
+M98 P'/path/to/macro/macro.g' R12
35
+;<-entity.command.gcode
36
+;^constant.numeric.command.gcode
37
+;   ^keyword.param.gcode
38
+;    ^punctuation.quote.single.open.gcode
39
+;       ^string.quoted.single.gcode
40
+;                           ^punctuation.quote.single.close.gcode
41
+
42
+M98 P"/path/to/macro/macro.g" R12
43
+;<-entity.command.gcode
44
+;^constant.numeric.command.gcode
45
+;   ^keyword.param.gcode
46
+;    ^punctuation.quote.double.open.gcode
47
+;       ^string.quoted.double.gcode
48
+;                           ^punctuation.quote.double.close.gcode
49
+
50
+M32 S100 P0 !/path/file.gco#
51
+;<-entity.command.gcode
52
+;^constant.numeric.command.gcode
53
+;   ^keyword.param.gcode
54
+;    ^constant.numeric.param.gcode
55
+;           ^punctuation.string.path.open.gcode
56
+;                ^string.unquoted.path.gcode
57
+;                          ^punctuation.string.path.close.gcode
58
+
59
+G28 ; Home All
60
+;<-entity.command.gcode
61
+;^constant.numeric.command.gcode
62
+;   ^punctuation.comment.eol.start
63
+;     ^comment.gcode
64
+
65
+N123 G1 X5 Y0 *64 ; EOL Comment
66
+;<-entity.nword.gcode
67
+;^constant.numeric.line-number.gcode
68
+;    ^entity.command.gcode
69
+;     ^constant.numeric.command.gcode
70
+;       ^keyword.param.gcode
71
+;        ^constant.numeric.param.gcode
72
+;             ^punctuation.marker.checksum.gcode
73
+;              ^constant.numeric.checksum.gcode
74
+
75
+N234 G1 X-5 Y+2 *64 error
76
+;<-entity.nword.gcode
77
+;^constant.numeric.line-number.gcode
78
+;    ^entity.command.gcode
79
+;     ^constant.numeric.command.gcode
80
+;       ^keyword.param.gcode
81
+;        ^constant.numeric.param.gcode
82
+;               ^punctuation.marker.checksum.gcode
83
+;                ^constant.numeric.checksum.gcode
84
+;                  ^invalid.error.syntax.gcode
85
+
86
+N234 M107 *64     
87
+;              ^-invalid.error.syntax.gcode
88
+

Loading…
Cancel
Save