2018-07-13 04:30:13 +02:00
|
|
|
%YAML 1.2
|
|
|
|
---
|
|
|
|
#
|
|
|
|
# G-Code (RepRap, not ISO-6983)
|
2018-09-24 01:58:36 +02:00
|
|
|
# Author: @thinkyhead
|
2018-07-13 04:30:13 +02:00
|
|
|
#
|
|
|
|
# RapRap G-Code is very simple.
|
|
|
|
#
|
|
|
|
# TODO: Lines that start with N get a different context, accepting a checksum.
|
|
|
|
#
|
|
|
|
name: G-Code (RepRap)
|
|
|
|
file_extensions:
|
2019-02-17 02:46:30 +01:00
|
|
|
- [ g, gco, gcode ]
|
2018-07-13 04:30:13 +02:00
|
|
|
scope: source.gcode
|
|
|
|
variables:
|
2019-02-17 02:46:30 +01:00
|
|
|
decimal: '[+-]?\d+(\.\d*)?'
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
contexts:
|
|
|
|
prototype:
|
|
|
|
- match: \s+
|
|
|
|
|
|
|
|
- include: mixin_comment
|
|
|
|
|
|
|
|
- match: $
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
main:
|
2019-02-17 02:46:30 +01:00
|
|
|
- meta_scope: line.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
- match: '([Nn]\s*(\d+))'
|
|
|
|
captures:
|
2019-02-17 02:46:30 +01:00
|
|
|
1: entity.nword.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
2: constant.numeric.line-number.gcode
|
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: gcode_command
|
|
|
|
|
|
|
|
# G, M, or T command
|
|
|
|
gcode_command:
|
|
|
|
- meta_content_scope: ctx.command.gcode
|
|
|
|
|
|
|
|
# M20 S2 P/path/to/file/name.gco
|
2019-02-17 02:46:30 +01:00
|
|
|
- match: ([Mm](20))\s*((S)(2)\s*(P))
|
2018-07-13 04:30:13 +02:00
|
|
|
captures:
|
|
|
|
1: entity.command.gcode markup.bold.gcode
|
|
|
|
2: constant.numeric.command.gcode
|
|
|
|
3: ctx.params.gcode
|
|
|
|
4: keyword.param.gcode
|
|
|
|
5: constant.numeric.param.gcode
|
|
|
|
6: keyword.param.gcode
|
|
|
|
set: gcode_string_arg
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
# M117 or M118 - Commands taking a string
|
2018-07-13 04:30:13 +02:00
|
|
|
- match: ([Mm]\s*(11[78]))\b
|
|
|
|
captures:
|
|
|
|
1: entity.command.gcode markup.bold.gcode
|
|
|
|
2: constant.numeric.command.gcode
|
|
|
|
set: gcode_string_arg
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
# Other commands, followed by data
|
|
|
|
- match: ([GMTgmt]\s*(\d+)((\.)(\d+))?)
|
2018-07-13 04:30:13 +02:00
|
|
|
captures:
|
|
|
|
1: entity.command.gcode markup.bold.gcode
|
|
|
|
2: constant.numeric.command.gcode
|
|
|
|
4: entity.separator.subcode
|
|
|
|
5: constant.numeric.subcode
|
|
|
|
set: gcode_params
|
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: syntax_error
|
|
|
|
|
|
|
|
# Parameters of a command
|
|
|
|
gcode_params:
|
|
|
|
- meta_content_scope: ctx.params.gcode
|
|
|
|
|
|
|
|
# M32 [S<pos>] [P<bool>] !/path/file.gco#
|
2019-02-17 02:46:30 +01:00
|
|
|
- match: \!
|
|
|
|
scope: punctuation.string.path.open.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
push: gcode_path_arg
|
|
|
|
|
|
|
|
# asterisk starts a checksum
|
|
|
|
- match: \*
|
2019-02-17 02:46:30 +01:00
|
|
|
scope: punctuation.marker.checksum.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
set: gcode_checksum
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
# parameter and single-quoted value
|
|
|
|
- match: ([A-Za-z])\s*(')
|
|
|
|
captures:
|
|
|
|
1: keyword.param.gcode
|
|
|
|
2: punctuation.quote.single.open.gcode
|
|
|
|
push: gcode_string_arg_quoted_single
|
|
|
|
|
|
|
|
# parameter and double-quoted value
|
|
|
|
- match: ([A-Za-z])\s*(")
|
|
|
|
captures:
|
|
|
|
1: keyword.param.gcode
|
|
|
|
2: punctuation.quote.double.open.gcode
|
|
|
|
push: gcode_string_arg_quoted_double
|
|
|
|
|
2019-05-12 00:45:10 +02:00
|
|
|
# parameter and list of values
|
|
|
|
- match: ([Ee])\s*(({{decimal}}\s*:\s*)+{{decimal}})
|
|
|
|
captures:
|
|
|
|
1: keyword.param.gcode
|
|
|
|
2: constant.numeric.param.gcode
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
# parameter and numeric value
|
2018-07-13 04:30:13 +02:00
|
|
|
- match: ([A-Za-z])\s*({{decimal}})
|
|
|
|
captures:
|
|
|
|
1: keyword.param.gcode
|
|
|
|
2: constant.numeric.param.gcode
|
|
|
|
|
|
|
|
# parameter with no value
|
|
|
|
- match: '[A-Za-z]'
|
|
|
|
scope: keyword.param.gcode
|
|
|
|
set: gcode_params
|
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: syntax_error
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
gcode_string_arg_quoted_single:
|
|
|
|
- meta_content_scope: string.quoted.single.gcode
|
|
|
|
|
|
|
|
- match: ([^'\\]+)
|
|
|
|
|
|
|
|
- match: (\\)
|
|
|
|
scope: punctuation.string.escape.gcode
|
|
|
|
push: escape_char
|
|
|
|
|
|
|
|
- match: (')
|
|
|
|
scope: punctuation.quote.single.close.gcode
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: syntax_error
|
|
|
|
|
|
|
|
gcode_string_arg_quoted_double:
|
|
|
|
- meta_content_scope: string.quoted.double.gcode
|
|
|
|
|
|
|
|
- match: ([^"\\]+)
|
|
|
|
|
|
|
|
- match: (\\)
|
|
|
|
scope: punctuation.string.escape.gcode
|
|
|
|
push: escape_char
|
|
|
|
|
|
|
|
- match: (")
|
|
|
|
scope: punctuation.quote.double.close.gcode
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: syntax_error
|
|
|
|
|
2018-07-13 04:30:13 +02:00
|
|
|
gcode_string_arg:
|
|
|
|
- meta_content_scope: ctx.string.gcode
|
|
|
|
|
|
|
|
- match: ([^;]+)
|
|
|
|
scope: string.unquoted.gcode
|
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
escape_char:
|
|
|
|
- meta_scope: string.escape.gcode punctuation.string.escape.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
|
2019-02-17 02:46:30 +01:00
|
|
|
- match: '.'
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
gcode_path_arg:
|
|
|
|
- meta_content_scope: string.unquoted.path.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
- match: (#)
|
2019-02-17 02:46:30 +01:00
|
|
|
scope: punctuation.string.path.close.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
pop: true
|
|
|
|
|
|
|
|
gcode_checksum:
|
2019-02-17 02:46:30 +01:00
|
|
|
- meta_content_scope: constant.numeric.checksum.gcode
|
|
|
|
- meta_include_prototype: false
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
- match: \d+
|
2019-02-17 02:46:30 +01:00
|
|
|
|
|
|
|
- match: ( *)$
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
- include: mixin_comment
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
- match: ()
|
|
|
|
set: syntax_error
|
|
|
|
|
|
|
|
# Done interpreting to the end of the line
|
|
|
|
gcode_line_done:
|
|
|
|
- match: \s*$
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
# Comments begin with a ';' and finish at the end of the line.
|
|
|
|
mixin_comment:
|
|
|
|
- match: ^\s*;
|
2019-02-17 02:46:30 +01:00
|
|
|
scope: punctuation.comment.line.start
|
2018-07-13 04:30:13 +02:00
|
|
|
set: gcode_comment
|
|
|
|
- match: \s*;
|
2019-02-17 02:46:30 +01:00
|
|
|
scope: punctuation.comment.eol.start
|
2018-07-13 04:30:13 +02:00
|
|
|
set: gcode_comment
|
2019-05-12 00:45:10 +02:00
|
|
|
- match: \s*\(
|
|
|
|
scope: punctuation.paren.comment.open
|
|
|
|
push: gcode_comment_paren
|
2018-07-13 04:30:13 +02:00
|
|
|
|
|
|
|
# Comment to end of line.
|
|
|
|
gcode_comment:
|
2019-02-17 02:46:30 +01:00
|
|
|
- meta_content_scope: comment.gcode
|
2018-07-13 04:30:13 +02:00
|
|
|
- match: \s*$
|
|
|
|
pop: true
|
|
|
|
|
2019-05-12 00:45:10 +02:00
|
|
|
gcode_comment_paren:
|
|
|
|
- meta_content_scope: paren.comment.gcode
|
|
|
|
|
|
|
|
- match: '[^)]+'
|
|
|
|
|
|
|
|
- match: '[)]'
|
|
|
|
scope: punctuation.paren.comment.close
|
|
|
|
pop: true
|
|
|
|
|
|
|
|
- match: \s*$
|
|
|
|
pop: true
|
|
|
|
|
2018-07-13 04:30:13 +02:00
|
|
|
# Everything after this point is broken by a syntax error
|
|
|
|
syntax_error:
|
|
|
|
- meta_scope: invalid.error.syntax.gcode
|
|
|
|
|
|
|
|
- match: .*$
|
|
|
|
pop: true
|