Skip to content

Commit 166cd25

Browse files
committed
fix(vscode): optimize tmLanguage definition
closes #266 and partly #265
1 parent c491e68 commit 166cd25

File tree

1 file changed

+156
-54
lines changed

1 file changed

+156
-54
lines changed

syntaxes/robotframework.tmLanguage.json

Lines changed: 156 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
{
22
"$schema": "https://raw.githubusercontent.com/RedCMD/TmLanguage-Syntax-Highlighter/main/vscode.tmLanguage.schema.json",
33
"repository": {
4-
"header": {
5-
"name": "keyword.other.header.robotframework",
6-
"match": "(^\\*\\*\\*.*?\\*\\*\\*)|((?<=^\\|)\\s+\\*\\*\\*.*?\\*\\*\\*)"
7-
},
84
"variable_setting": {
95
"name": "meta.variable.assign.robotframework",
106
"contentName": "string.unquoted.argument.robotframework",
@@ -15,14 +11,23 @@
1511
"3": { "name": "punctuation.definition.variable.end.robotframework" },
1612
"4": { "name": "keyword.operator.robotframework" }
1713
},
18-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
14+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
1915
"patterns": [
2016
{ "include": "#escape" },
2117
{ "include": "#comment" },
2218
{ "include": "#line_continuation" },
2319
{ "include": "#variables" }
2420
]
2521
},
22+
"variables_section": {
23+
"begin": "^(\\*+\\s*(?i:variables?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
24+
"beginCaptures": { "1": { "name": "keyword.other.header.variable.robotframework" } },
25+
"end": "^(?=\\*)",
26+
"patterns": [
27+
{ "include": "#variable_setting" },
28+
{ "include": "#comment_line" }
29+
]
30+
},
2631
"variables": {
2732
"patterns": [
2833
{ "include": "#simple_var" },
@@ -70,75 +75,168 @@
7075
},
7176
"patterns": [ { "include": "#variables" } ]
7277
},
73-
"comment": {
78+
"comment_line": {
7479
"name": "comment.block.robotframework",
75-
"match": "(?:^ *|\\t+| {2,})(#.*)$",
80+
"match": "^\\s*(#.*)$",
7681
"captures": { "1": { "name": "comment.line.robotframework" } }
7782
},
78-
"setting": {
79-
"patterns": [
80-
{ "include": "#documentation_setting" },
81-
{ "include": "#other_setting" }
82-
]
83+
"comment": {
84+
"name": "comment.block.robotframework",
85+
"match": "( {2}| ?\\t)\\s*(#.*)$",
86+
"captures": { "0": { "name": "comment.line.rest.robotframework" } }
8387
},
8488
"escape": {
8589
"patterns": [
8690
{ "include": "#escape-sequence-unicode" },
8791
{ "include": "#escape-sequence" }
8892
]
8993
},
94+
"settings_section": {
95+
"begin": "^(\\*+\\s*(?i:settings?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
96+
"beginCaptures": { "1": { "name": "keyword.other.header.settings.robotframework" } },
97+
"end": "^(?=\\*)",
98+
"patterns": [
99+
{ "include": "#comment_line" },
100+
{ "include": "#documentation_setting" },
101+
{ "include": "#other_setting" },
102+
{ "include": "#unknown_setting" }
103+
]
104+
},
90105
"documentation_setting": {
91106
"contentName": "markup.robotframework",
92107
"begin": "(?i)^(documentation|dokumentation|Tài liệu hướng dẫn)(?= {2}| ?\\t| ?$)",
93-
"beginCaptures": { "1": { "name": "keyword.control.settings.robotframework" } },
94-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
108+
"beginCaptures": { "1": { "name": "keyword.control.global.settings.documentation.robotframework" } },
109+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
95110
"patterns": [
111+
{ "include": "#comment" },
112+
{ "include": "#comment_line" },
96113
{ "include": "#documentation_italic" },
97114
{ "include": "#documentation_bold" },
98115
{ "include": "#escape" },
99-
{ "include": "#comment" },
100116
{ "include": "#variables" },
101117
{ "include": "#line_continuation" }
102118
]
103119
},
104120
"documentation_bold": {
105121
"contentName": "markup.bold.documentation.robotframework",
106-
"begin": "\\*",
107-
"end": "\\*|$",
108-
"beginCaptures": { "0": { "name": "markup.robotframework" } },
109-
"endCaptures": { "0": { "name": "markup.robotframework" } },
122+
"begin": "(\\*)(\\**)",
123+
"end": "(\\*)*(\\*)|$",
124+
"beginCaptures": { "1": { "name": "markup.robotframework" } },
125+
"endCaptures": { "2": { "name": "markup.robotframework" } },
110126
"patterns": [
111127
{ "include": "#documentation_italic" },
112-
{ "include": "#documentation_bold" },
113128
{ "include": "#escape" },
114129
{ "include": "#comment" },
130+
{ "include": "#comment_line" },
115131
{ "include": "#variables" },
116132
{ "include": "#line_continuation" }
117133
]
118134
},
119135
"documentation_italic": {
120136
"contentName": "markup.italic.documentation.robotframework",
121-
"begin": "_",
122-
"end": "_|$",
123-
"beginCaptures": { "0": { "name": "markup.robotframework" } },
124-
"endCaptures": { "0": { "name": "markup.robotframework" } },
137+
"begin": "(_)(_*)",
138+
"end": "(_*)(_)|$",
139+
"beginCaptures": { "1": { "name": "markup.robotframework" } },
140+
"endCaptures": { "2": { "name": "markup.robotframework" } },
125141
"patterns": [
126-
{ "include": "#documentation_italic" },
127142
{ "include": "#documentation_bold" },
128143
{ "include": "#escape" },
129144
{ "include": "#comment" },
145+
{ "include": "#comment_line" },
130146
{ "include": "#variables" },
131147
{ "include": "#line_continuation" }
132148
]
133149
},
150+
"testcase_name": {
151+
"contentName": "string.unquoted.argument.robotframework",
152+
"begin": "^( ?\\S+ ?\\S*)(?= {2}| ?\\t| ?$)",
153+
"beginCaptures": { "1": { "name": "entity.name.function.testcase.name.robotframework" } },
154+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))"
155+
},
156+
"keyword_name": {
157+
"contentName": "string.unquoted.argument.robotframework",
158+
"begin": "^( ?\\S+ ?\\S*)(?= {2}| ?\\t| ?$)",
159+
"beginCaptures": { "1": { "name": "entity.name.function.keyword.name.robotframework" } },
160+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))"
161+
},
162+
"block_statements": {
163+
"patterns": [
164+
{ "include": "#testcase_settings" },
165+
{ "include": "#control_flow_expression_statements" },
166+
{ "include": "#control_flow_statements" },
167+
{ "include": "#other_statements" },
168+
{ "include": "#keyword_call" },
169+
{ "include": "#returning_keyword_call" }
170+
]
171+
},
172+
"testcases_section": {
173+
"begin": "^(\\*+\\s*(?i:test cases?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
174+
"beginCaptures": { "1": { "name": "keyword.other.header.testcase.robotframework" } },
175+
"end": "^(?=\\*)",
176+
"patterns": [
177+
{ "include": "#testcase_name" },
178+
{ "include": "#block_statements" }
179+
]
180+
},
181+
"tasks_section": {
182+
"begin": "^(\\*+\\s*(?i:tasks?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
183+
"beginCaptures": { "1": { "name": "keyword.other.header.task.robotframework" } },
184+
"end": "^(?=\\*)",
185+
"patterns": [
186+
{ "include": "#testcase_name" },
187+
{ "include": "#block_statements" }
188+
]
189+
},
190+
"keywords_section": {
191+
"begin": "^(\\*+\\s*(?i:keywords?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
192+
"beginCaptures": { "1": { "name": "keyword.other.header.keyword.robotframework" } },
193+
"end": "^(?=\\*)",
194+
"patterns": [
195+
{ "include": "#keyword_name" },
196+
{ "include": "#block_statements" }
197+
]
198+
},
199+
"comments_section": {
200+
"begin": "^(\\*+\\s*(?i:comments?)( ?\\*+)?)(?= {2}| ?\\t| ?$)",
201+
"beginCaptures": { "1": { "name": "keyword.other.header.comment.robotframework" } },
202+
"end": "^(?=\\*)",
203+
"patterns": [
204+
{ "include": "#comment_line" },
205+
{ "include": "#block_comment" }
206+
]
207+
},
208+
"section": {
209+
"begin": "^(\\*+\\s*(.*)(\\s?\\*+)?)(?= {2}| ?\\t| ?$)",
210+
"beginCaptures": { "1": { "name": "keyword.other.header.robotframework" } },
211+
"end": "^(?=\\*)"
212+
},
213+
"block_comment": {
214+
"match": "^.*$",
215+
"name": "comment.block.robotframework"
216+
},
134217
"other_setting": {
135218
"contentName": "string.unquoted.argument.robotframework",
136219
"begin": "(?i)^(\\S+( \\S+)*)(?= {2}| ?\\t| ?$)",
137-
"beginCaptures": { "1": { "name": "keyword.control.settings.robotframework" } },
138-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
220+
"beginCaptures": { "1": { "name": "keyword.control.global.settings.robotframework" } },
221+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
222+
"patterns": [
223+
{ "include": "#testcase_settings" },
224+
{ "include": "#control_flow_expression_statements" },
225+
{ "include": "#control_flow_statements" },
226+
{ "include": "#other_statements" },
227+
{ "include": "#keyword_call" },
228+
{ "include": "#returning_keyword_call" }
229+
]
230+
},
231+
"unknown_setting": {
232+
"contentName": "comment.unknown.setting.arguments.robotframework",
233+
"begin": "(?i)^(\\s+)(\\S+( \\S+)*)(?= {2}| ?\\t| ?$)",
234+
"beginCaptures": { "2": { "name": "comment.unknown.setting.robotframework" } },
235+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
139236
"patterns": [
140237
{ "include": "#escape" },
141238
{ "include": "#comment" },
239+
{ "include": "#comment_line" },
142240
{ "include": "#variables" },
143241
{ "include": "#line_continuation" }
144242
]
@@ -151,26 +249,28 @@
151249
},
152250
"documentation_testcase_settings": {
153251
"contentName": "markup.robotframework",
154-
"begin": "(?i)(\\[(documentation|dokumentation|Tài liệu hướng dẫn)\\])(?= {2}| ?\\t| ?$)",
155-
"beginCaptures": { "0": { "name": "keyword.control.settings.robotframework" } },
156-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
252+
"begin": "(?i)^( {2}|\\t)(\\s)*(\\[documentation\\])(?= {2}| ?\\t| ?$)",
253+
"beginCaptures": { "3": { "name": "keyword.control.settings.documentation.robotframework" } },
254+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
157255
"patterns": [
158256
{ "include": "#documentation_italic" },
159257
{ "include": "#documentation_bold" },
160258
{ "include": "#escape" },
161259
{ "include": "#comment" },
260+
{ "include": "#comment_line" },
162261
{ "include": "#variables" },
163262
{ "include": "#line_continuation" }
164263
]
165264
},
166265
"other_testcase_settings": {
167266
"contentName": "string.unquoted.argument.robotframework",
168-
"begin": "(\\[.*?\\])(?= {2}| ?\\t| ?$)",
267+
"begin": "^( {2}|\\t)(\\s)*(\\[.*?\\])(?= {2}| ?\\t| ?$)",
169268
"beginCaptures": { "0": { "name": "keyword.control.settings.robotframework" } },
170-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
269+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
171270
"patterns": [
172271
{ "include": "#escape" },
173272
{ "include": "#comment" },
273+
{ "include": "#comment_line" },
174274
{ "include": "#variables" },
175275
{ "include": "#line_continuation" }
176276
]
@@ -179,10 +279,12 @@
179279
"name": "meta.keyword-call.content.robotframework",
180280
"contentName": "string.unquoted.argument.robotframework",
181281
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(.*?)(?= {2,}| ?\\t ?| ?$)",
182-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
282+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
183283
"beginCaptures": { "1": { "name": "entity.name.function.keyword-call.robotframework" } },
184284
"patterns": [
285+
{ "include": "#escape" },
185286
{ "include": "#comment" },
287+
{ "include": "#comment_line" },
186288
{ "include": "#variables" },
187289
{ "include": "#line_continuation" }
188290
]
@@ -191,7 +293,7 @@
191293
"name": "meta.keyword-call.content.robotframework",
192294
"contentName": "string.unquoted.argument.robotframework",
193295
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(IF|ELSE IF|WHILE)(( {2,}| ?\\t)( *)(.*?))?(?= {2,}| ?\\t ?| ?$)",
194-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
296+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
195297
"beginCaptures": {
196298
"1": { "name": "keyword.control.flow.robotframework" },
197299
"5": {
@@ -200,7 +302,9 @@
200302
}
201303
},
202304
"patterns": [
305+
{ "include": "#escape" },
203306
{ "include": "#comment" },
307+
{ "include": "#comment_line" },
204308
{ "include": "#variables" },
205309
{ "include": "#line_continuation" }
206310
]
@@ -209,10 +313,11 @@
209313
"name": "meta.keyword-call.content.robotframework",
210314
"contentName": "string.unquoted.argument.robotframework",
211315
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(FOR|END|ELSE|TRY|EXCEPT|FINALLY)(?= {2,}| ?\\t ?| ?$)",
212-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
316+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
213317
"beginCaptures": { "1": { "name": "keyword.control.flow.robotframework" } },
214318
"patterns": [
215319
{ "include": "#comment" },
320+
{ "include": "#comment_line" },
216321
{ "include": "#variables" },
217322
{ "include": "#line_continuation" }
218323
]
@@ -221,10 +326,12 @@
221326
"name": "meta.keyword-call.content.robotframework",
222327
"contentName": "string.unquoted.argument.robotframework",
223328
"begin": "^(?!(?: {2,}| ?\\t ?)+(?:(?=[$\\[@&%]|\\.)))(?: {2,}| ?\\t ?)+(VAR)(?= {2,}| ?\\t ?| ?$)",
224-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
329+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
225330
"beginCaptures": { "1": { "name": "keyword.robotframework" } },
226331
"patterns": [
332+
{ "include": "#escape" },
227333
{ "include": "#comment" },
334+
{ "include": "#comment_line" },
228335
{ "include": "#variables" },
229336
{ "include": "#line_continuation" }
230337
]
@@ -233,7 +340,7 @@
233340
"name": "meta.returning-keyword-call.robotframework",
234341
"contentName": "meta.returning.keyword.content.robotframework",
235342
"begin": "^(?=(?: {2,}| ?\\t ?)+(?:(?=[$@&])))(?:\\s)",
236-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
343+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
237344
"patterns": [ { "include": "#returning_keyword" } ]
238345
},
239346
"returning_keyword": {
@@ -247,7 +354,7 @@
247354
},
248355
"2": { "name": "entity.name.function.keyword-call.robotframework" }
249356
},
250-
"end": "^(?!(\\s*\\.\\.\\.)|(\\s+)|(\\s*#\\.*))",
357+
"end": "^(?!(\\s*(\\.\\.\\.((( {2}| ?\\t)\\s*\\S.*)|(\\s*))?$))|(\\s*#.*$)|(\\s*$))",
251358
"patterns": [
252359
{ "include": "#variables" },
253360
{ "include": "#line_continuation" },
@@ -265,12 +372,8 @@
265372
]
266373
},
267374
"line_continuation": {
268-
"match": "^(\\s*\\.\\.\\.)(?: {2,}| ?\\t+| ?$)",
269-
"captures": {
270-
"1": {
271-
"name": "keyword.operator.continue.robotframework"
272-
}
273-
}
375+
"match": "^(\\s*\\.\\.\\.)(?! ?\\S)",
376+
"captures": { "1": { "name": "keyword.operator.continue.robotframework" } }
274377
},
275378
"impossible": {
276379
"comment": "This is a special rule that should be used where no match is desired. It is not a good idea to match something like '1{0}' because in some cases that can result in infinite loops in token generation. So the rule instead matches and impossible expression to allow a match to fail and move to the next token.",
@@ -2395,16 +2498,15 @@
23952498
}
23962499
},
23972500
"patterns": [
2398-
{ "include": "#comment" },
2399-
{ "include": "#header" },
2400-
{ "include": "#variable_setting" },
2401-
{ "include": "#setting" },
2402-
{ "include": "#testcase_settings" },
2403-
{ "include": "#control_flow_expression_statements" },
2404-
{ "include": "#control_flow_statements" },
2405-
{ "include": "#other_statements" },
2406-
{ "include": "#keyword_call" },
2407-
{ "include": "#returning_keyword_call" }
2501+
{ "include": "#comment_line" },
2502+
{ "include": "#settings_section" },
2503+
{ "include": "#variables_section" },
2504+
{ "include": "#testcases_section" },
2505+
{ "include": "#tasks_section" },
2506+
{ "include": "#keywords_section" },
2507+
{ "include": "#comments_section" },
2508+
{ "include": "#section" },
2509+
{ "include": "#block_comment" }
24082510
],
24092511
"uuid": "a7fae509-bc8d-451e-b5fc-a47feb9d2a9e",
24102512
"fileTypes": [

0 commit comments

Comments
 (0)