-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGnomod.sublime-syntax
91 lines (77 loc) · 2.59 KB
/
Gnomod.sublime-syntax
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
%YAML 1.2
---
# License: https://github.com/mitranim/sublime-gomod#misc
file_extensions: [gno.mod, gno.work]
scope: source.gnomod
# Note: in Go 1.11, identifiers may include ANY non-whitespace except `//`. This
# means they may include `()` in any quantity and order. This latter part is
# probably an artifact of the implementation, unintuitive and likely to be
# changed in the future. At the time of writing, no valid `go.mod` should rely
# on this "feature", so we parse parens separately to future-proof the syntax.
variables:
ident_body: (?:[^\s/()]|/(?!/))+
ident_terminator: '//|\(|\)|\s|$'
ident: "{{ident_body}}(?={{ident_terminator}})"
contexts:
main:
- include: comment-match
- include: punctuation-match
- include: statement-match
nonroot-match:
- include: comment-match
- include: punctuation-match
- match: "{{ident}}"
scope: variable.gnomod
comment-match:
- match: //(?:.|\s)*
scope: comment.gnomod
punctuation-match:
- match: \(
scope: punctuation.section.parens.begin.gnomod
- match: \)
scope: punctuation.section.parens.end.gnomod
statement-match:
- match: (?:exclude|module|replace|require)(?={{ident_terminator}})
scope: keyword.gnomod
push: modvers-or-replacements-pop
- match: "{{ident}}"
scope: keyword.gnomod
push:
- include: before-eol-or-comment-pop
- include: nonroot-match
# For code after `exclude`, `replace` or `require`:
# package
# package version
# package [version] => package [version]
modvers-or-replacements-pop:
- match: \(
scope: punctuation.section.parens.begin.gnomod
set:
- match: \)
scope: punctuation.section.parens.end.gnomod
# Note: go.mod expects only comments after a closing paren
set:
- include: comment-match
- include: before-eol-or-comment-pop
- include: comment-match
- include: modver-or-replacement-match
- include: before-eol-or-comment-pop
- include: modver-or-replacement-match
modver-or-replacement-match:
- match: (?=\))
pop: true
- match: =>(?={{ident_terminator}})
scope: keyword.operator.gnomod
- match: '({{ident_body}})\s+(=>)(?={{ident_terminator}})'
captures:
1: variable.gnomod
2: keyword.operator.gnomod
- match: '({{ident_body}})\s+({{ident_body}})(?={{ident_terminator}})'
captures:
1: variable.gnomod
2: string.version.gnomod
- match: "{{ident}}"
scope: variable.gnomod
before-eol-or-comment-pop:
- match: (?=//|$)
pop: true