Переглянути джерело

Update G-code syntax for Sublime

Scott Lahteine 6 роки тому
джерело
коміт
c041eec699

+ 76
- 22
buildroot/share/sublime/RepRapTools/G-Code.sublime-syntax Переглянути файл

10
 #
10
 #
11
 name: G-Code (RepRap)
11
 name: G-Code (RepRap)
12
 file_extensions:
12
 file_extensions:
13
-  - [ gco, gcode ]
13
+  - [ g, gco, gcode ]
14
 scope: source.gcode
14
 scope: source.gcode
15
 variables:
15
 variables:
16
-  decimal:  '[+-]?\d+(\.(\d+)?)?'
16
+  decimal: '[+-]?\d+(\.\d*)?'
17
 
17
 
18
 contexts:
18
 contexts:
19
   prototype:
19
   prototype:
25
       pop: true
25
       pop: true
26
 
26
 
27
   main:
27
   main:
28
-    - meta_content_scope: ctx.line.gcode
28
+    - meta_scope: line.gcode
29
 
29
 
30
     - match: '([Nn]\s*(\d+))'
30
     - match: '([Nn]\s*(\d+))'
31
       captures:
31
       captures:
32
-        1: ctx.gcode_line_num
32
+        1: entity.nword.gcode
33
         2: constant.numeric.line-number.gcode
33
         2: constant.numeric.line-number.gcode
34
 
34
 
35
     - match: ()
35
     - match: ()
40
     - meta_content_scope: ctx.command.gcode
40
     - meta_content_scope: ctx.command.gcode
41
 
41
 
42
     # M20 S2 P/path/to/file/name.gco
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
       captures:
44
       captures:
45
         1: entity.command.gcode markup.bold.gcode
45
         1: entity.command.gcode markup.bold.gcode
46
         2: constant.numeric.command.gcode
46
         2: constant.numeric.command.gcode
50
         6: keyword.param.gcode
50
         6: keyword.param.gcode
51
       set: gcode_string_arg
51
       set: gcode_string_arg
52
 
52
 
53
-    # command followed by data
53
+    # M117 or M118 - Commands taking a string
54
     - match: ([Mm]\s*(11[78]))\b
54
     - match: ([Mm]\s*(11[78]))\b
55
       captures:
55
       captures:
56
         1: entity.command.gcode markup.bold.gcode
56
         1: entity.command.gcode markup.bold.gcode
57
         2: constant.numeric.command.gcode
57
         2: constant.numeric.command.gcode
58
       set: gcode_string_arg
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
       captures:
62
       captures:
63
         1: entity.command.gcode markup.bold.gcode
63
         1: entity.command.gcode markup.bold.gcode
64
         2: constant.numeric.command.gcode
64
         2: constant.numeric.command.gcode
74
     - meta_content_scope: ctx.params.gcode
74
     - meta_content_scope: ctx.params.gcode
75
 
75
 
76
     # M32 [S<pos>] [P<bool>] !/path/file.gco#
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
       push: gcode_path_arg
79
       push: gcode_path_arg
80
 
80
 
81
     # asterisk starts a checksum
81
     # asterisk starts a checksum
82
     - match: \*
82
     - match: \*
83
-      scope: entity.checksum.gcode
83
+      scope: punctuation.marker.checksum.gcode
84
       set: gcode_checksum
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
     - match: ([A-Za-z])\s*({{decimal}})
101
     - match: ([A-Za-z])\s*({{decimal}})
88
       captures:
102
       captures:
89
         1: keyword.param.gcode
103
         1: keyword.param.gcode
97
     - match: ()
111
     - match: ()
98
       set: syntax_error
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
   gcode_string_arg:
146
   gcode_string_arg:
101
     - meta_content_scope: ctx.string.gcode
147
     - meta_content_scope: ctx.string.gcode
102
 
148
 
103
     - match: ([^;]+)
149
     - match: ([^;]+)
104
       scope: string.unquoted.gcode
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
     - match: (#)
161
     - match: (#)
113
-      scope: entity.string.path.close.gcode
162
+      scope: punctuation.string.path.close.gcode
114
       pop: true
163
       pop: true
115
 
164
 
116
   gcode_checksum:
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
     - match: \d+
169
     - match: \d+
120
-      scope: constant.numeric.checksum.gcode
170
+
171
+    - match: ( *)$
172
+      pop: true
173
+
174
+    - include: mixin_comment
121
 
175
 
122
     - match: ()
176
     - match: ()
123
       set: syntax_error
177
       set: syntax_error
130
   # Comments begin with a ';' and finish at the end of the line.
184
   # Comments begin with a ';' and finish at the end of the line.
131
   mixin_comment:
185
   mixin_comment:
132
     - match: ^\s*;
186
     - match: ^\s*;
133
-      scope: punctuation.definition.comment.line.start
187
+      scope: punctuation.comment.line.start
134
       set: gcode_comment
188
       set: gcode_comment
135
     - match: \s*;
189
     - match: \s*;
136
-      scope: punctuation.definition.comment.eol.start
190
+      scope: punctuation.comment.eol.start
137
       set: gcode_comment
191
       set: gcode_comment
138
 
192
 
139
   # Comment to end of line.
193
   # Comment to end of line.
140
   gcode_comment:
194
   gcode_comment:
141
-    - meta_scope: comment.gcode
195
+    - meta_content_scope: comment.gcode
142
     - match: \s*$
196
     - match: \s*$
143
       pop: true
197
       pop: true
144
 
198
 

+ 88
- 0
buildroot/share/sublime/RepRapTools/syntax_test_G-code.gcode Переглянути файл

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
+

Завантаження…
Відмінити
Зберегти