-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcmd-help.sublime-syntax
206 lines (175 loc) · 5.31 KB
/
cmd-help.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
%YAML 1.2
---
name: Command Help
file_extensions:
- cmd-help # doesn't really exist, but useful for the shortname
scope: text.cmd-help
variables:
### section name variables:
# lowercase, uppercase or dash char (for compound words)
alpha_dash: '[[:alpha:]-]'
# all kinds of words, including those within 1/2 parentheses
any_word: '\(?{{alpha_dash}}+\b\)?'
# words starting with uppercase
leading_word: '[:upper:]({{alpha_dash}})*\b'
### command option variables:
option_stop: '[ \t\n,=\[</]'
# marks seen in option names: . ? : # $ --
option_name: '[^{{option_stop}}]+'
### command/option argument variables:
ellipsis: '\.\.\.'
allcaps_argument_name: '[:upper:][[:upper:][:digit:]_]*\b'
relaxed_argument_name: '[:alpha:][[:alnum:]_-]*\b'
scope_variables: # rightmost scope is matched first
section_heading_scope: &SECTION_HEADING_SCOPE
constant.section-heading.cmd-help string.section-heading.cmd-help
markup.heading.cmd-help entity.name.section.cmd-help
inline_usage_scope: &INLINE_USAGE_SCOPE
constant.section-heading.cmd-help string.inline-usage.cmd-help
markup.heading.inline-usage.cmd-help entity.name.section.inline-usage.cmd-help
def_option_scope: &DEF_OPTION_SCOPE
entity.name.function.option.cmd-help
end_of_options_scope: &END_OF_OPTIONS_SCOPE
keyword.control.end-of-options.cmd-help
option_argument_scope: &OPTION_ARGUMENT_SCOPE
string.option-argument.cmd-help variable.other.option-argument.cmd-help
variable.parameter.option-argument.cmd-help
contexts:
prototype:
# abort if color escape codes
- match: '(?=.*\e\[0m)'
set: sink
# abort if formatted with backspace
- match: '(?=.*[\b])'
set: sink
main: # stack lv 0
- match: '^'
push: [line, line-begin]
sink:
- clear_scopes: true
- meta_include_prototype: false
line: # stack lv 1
- match: '$'
pop: true
### helpers ##################################################################
else-pop:
- include: eol-pop # '.' doesn't match '\n'
- match: '(?=.)'
pop: true
eol-pop:
- match: '\n'
pop: true
then-pop:
- match: ''
pop: true
### stack lv 2 ###############################################################
line-begin:
- match: '^(?=\S)'
set: indent-0
- match: '^ {1,2}(?=\S)'
set: indent-1-2
- match: '^ {3,8}(?=\S)'
set: indent-3-8
- match: '^\t{1,2}(?=\S)'
set: indent-3-8
- include: else-pop
indent-0:
- include: maybe-heading
- include: maybe-option
- include: else-pop
indent-1-2:
- include: maybe-option
- include: maybe-heading
- include: else-pop
indent-3-8:
- include: maybe-option
- include: else-pop
# maybe-x contexts can be included sequentially for OR-like behavior
maybe-heading:
- include: heading-specials
- match: '(?=.{1,40}\n)'
# only consider lines <= 40 chars long
set: heading-general
maybe-option:
- match: '(?=-)'
set: def-option
heading-general:
- match: '{{leading_word}}( {{any_word}})*:?\n'
scope: *SECTION_HEADING_SCOPE
set: then-pop
- include: else-pop
# - match: '{{any_word}}( {{any_word}})*:\n'
# scope: *SECTION_HEADING_SCOPE
# set: then-pop
heading-specials:
- match: '(?i:usage):(?=.+\n)'
scope: *INLINE_USAGE_SCOPE
set: then-pop
- match: '(positional arguments|optional arguments|options):\n'
scope: *SECTION_HEADING_SCOPE
set: then-pop
def-option:
- match: '---'
# probably not an option
pop: true
- match: '--(?=\s)'
scope: *END_OF_OPTIONS_SCOPE
set: then-pop
- match: '-{{option_name}}'
scope: *DEF_OPTION_SCOPE
set: def-option-post
- include: else-pop
def-option-post:
- include: connect-option-alias
- match: ' '
set: space-after-option
- match: '='
set: equals-after-option
# alt: match directly in option-argument and colorize '=' too?
- match: '\[=|\['
set: square-brackets-after-option
- include: else-pop
connect-option-alias:
- match: ', '
set: def-option
- match: ' \| '
set: def-option
- match: ' (?=-)'
set: def-option
- match: ' or '
set: def-option
- match: '/'
set: def-option
- match: '\s+(?=-)'
set: def-option
space-after-option:
- match: '<.*?>'
scope: *OPTION_ARGUMENT_SCOPE
set: option-argument-post
- match: '{{allcaps_argument_name}}\b'
scope: *OPTION_ARGUMENT_SCOPE
set: option-argument-post
- match: '{{relaxed_argument_name}}(?! [:alpha:])'
scope: *OPTION_ARGUMENT_SCOPE
set: option-argument-post
- include: else-pop
equals-after-option:
- match: '{{relaxed_argument_name}}'
scope: *OPTION_ARGUMENT_SCOPE
set: option-argument-post
- match: '<.*?>'
scope: *OPTION_ARGUMENT_SCOPE
set: option-argument-post
- include: else-pop
square-brackets-after-option:
- meta_content_scope: *OPTION_ARGUMENT_SCOPE
- match: '(?=])'
#fixme: should consume (no lookahead), this forces else-pop on option-argument-post
set: option-argument-post
option-argument-post:
- match: '({{ellipsis}})?'
scope: *OPTION_ARGUMENT_SCOPE
# - match: ''
# set: def-option-post
- include: connect-option-alias
- include: else-pop