Procházet zdrojové kódy

Add Sublime G-code (RepRap) syntax

Scott Lahteine před 6 roky
rodič
revize
c8d24a6412

+ 149
- 0
buildroot/share/sublime/RepRapTools/G-Code.sublime-syntax Zobrazit soubor

@@ -0,0 +1,149 @@
1
+%YAML 1.2
2
+---
3
+#
4
+# G-Code (RepRap, not ISO-6983)
5
+#
6
+# RapRap G-Code is very simple.
7
+#
8
+# TODO: Lines that start with N get a different context, accepting a checksum.
9
+#
10
+name: G-Code (RepRap)
11
+file_extensions:
12
+  - [ gco, gcode ]
13
+scope: source.gcode
14
+variables:
15
+  decimal:  '[+-]?\d+(\.(\d+)?)?'
16
+
17
+contexts:
18
+  prototype:
19
+    - match: \s+
20
+
21
+    - include: mixin_comment
22
+
23
+    - match: $
24
+      pop: true
25
+
26
+  main:
27
+    - meta_content_scope: ctx.line.gcode
28
+
29
+    - match: '([Nn]\s*(\d+))'
30
+      captures:
31
+        1: ctx.gcode_line_num
32
+        2: constant.numeric.line-number.gcode
33
+
34
+    - match: ()
35
+      set: gcode_command
36
+
37
+  # G, M, or T command
38
+  gcode_command:
39
+    - meta_content_scope: ctx.command.gcode
40
+
41
+    # M20 S2 P/path/to/file/name.gco
42
+    - match: ([Mm](20))(\s*(S)(2)\s*(P))
43
+      captures:
44
+        1: entity.command.gcode markup.bold.gcode
45
+        2: constant.numeric.command.gcode
46
+        3: ctx.params.gcode
47
+        4: keyword.param.gcode
48
+        5: constant.numeric.param.gcode
49
+        6: keyword.param.gcode
50
+      set: gcode_string_arg
51
+
52
+    # command followed by data
53
+    - match: ([Mm]\s*(11[78]))\b
54
+      captures:
55
+        1: entity.command.gcode markup.bold.gcode
56
+        2: constant.numeric.command.gcode
57
+      set: gcode_string_arg
58
+
59
+    # command followed by data
60
+    - match: '([GMTgmt]\s*(\d+)((\.)(\d+))?)'
61
+      captures:
62
+        1: entity.command.gcode markup.bold.gcode
63
+        2: constant.numeric.command.gcode
64
+        4: entity.separator.subcode
65
+        5: constant.numeric.subcode
66
+      set: gcode_params
67
+
68
+    - match: ()
69
+      set: syntax_error
70
+
71
+  # Parameters of a command
72
+  gcode_params:
73
+    - meta_content_scope: ctx.params.gcode
74
+
75
+    # M32 [S<pos>] [P<bool>] !/path/file.gco#
76
+    - match: '!'
77
+      scope: entity.string.filename.open
78
+      push: gcode_path_arg
79
+
80
+    # asterisk starts a checksum
81
+    - match: \*
82
+      scope: entity.checksum.gcode
83
+      set: gcode_checksum
84
+
85
+    # parameter and value
86
+    - match: ([A-Za-z])\s*({{decimal}})
87
+      captures:
88
+        1: keyword.param.gcode
89
+        2: constant.numeric.param.gcode
90
+
91
+    # parameter with no value
92
+    - match: '[A-Za-z]'
93
+      scope: keyword.param.gcode
94
+      set: gcode_params
95
+
96
+    - match: ()
97
+      set: syntax_error
98
+
99
+  gcode_string_arg:
100
+    - meta_content_scope: ctx.string.gcode
101
+
102
+    - match: ([^;]+)
103
+      scope: string.unquoted.gcode
104
+
105
+  gcode_path_arg:
106
+    - meta_content_scope: ctx.path.gcode
107
+
108
+    - match: ([^#]+)
109
+      scope: string.unquoted.path.gcode
110
+
111
+    - match: (#)
112
+      scope: entity.string.path.close.gcode
113
+      pop: true
114
+
115
+  gcode_checksum:
116
+    - meta_content_scope: ctx.checksum.gcode
117
+
118
+    - match: \d+
119
+      scope: constant.numeric.checksum.gcode
120
+
121
+    - match: ()
122
+      set: syntax_error
123
+
124
+  # Done interpreting to the end of the line
125
+  gcode_line_done:
126
+    - match: \s*$
127
+      pop: true
128
+
129
+  # Comments begin with a ';' and finish at the end of the line.
130
+  mixin_comment:
131
+    - match: ^\s*;
132
+      scope: punctuation.definition.comment.line.start
133
+      set: gcode_comment
134
+    - match: \s*;
135
+      scope: punctuation.definition.comment.eol.start
136
+      set: gcode_comment
137
+
138
+  # Comment to end of line.
139
+  gcode_comment:
140
+    - meta_scope: comment.gcode
141
+    - match: \s*$
142
+      pop: true
143
+
144
+  # Everything after this point is broken by a syntax error
145
+  syntax_error:
146
+    - meta_scope: invalid.error.syntax.gcode
147
+
148
+    - match: .*$
149
+      pop: true

Loading…
Zrušit
Uložit