Skip to content

Commit 3cc8251

Browse files
glcraftgly
andauthored
Fix use syntax (#79)
* add braced pattern * use module: add emergency case * use starts beginning onf line * use: symbol optional * use from filename * better path in use * better module name highlight * restrain quoted symbol names * Add optional comma between symbol --------- Co-authored-by: gly <[email protected]>
1 parent f37c697 commit 3cc8251

File tree

1 file changed

+88
-6
lines changed

1 file changed

+88
-6
lines changed

syntaxes/nushell.tmLanguage.json

Lines changed: 88 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -345,12 +345,94 @@
345345
]
346346
},
347347
"use-module": {
348-
"match": "((?:export )?use)\\s+([\\w\\-]+)(?:\\s+([\\w\\-]+|\"[\\w\\- ]+\"|\\*))?;?",
349-
"captures": {
350-
"1": { "name": "entity.name.function.nushell" },
351-
"2": { "name": "entity.name.namespace.nushell" },
352-
"3": { "name": "keyword.other.nushell" }
353-
}
348+
"patterns": [
349+
{
350+
"match": "^\\s*((?:export )?use)\\s+([\\w\\-]+|\"[\\w\\- ]+\"|'[\\w\\- ]+')(?:\\s+([\\w\\-]+|\"[\\w\\- ]+\"|'[\\w\\- ]+'|\\*))?\\s*;?$",
351+
"captures": {
352+
"1": { "name": "entity.name.function.nushell" },
353+
"2": { "name": "entity.name.namespace.nushell" },
354+
"3": { "name": "keyword.other.nushell" }
355+
}
356+
},
357+
{
358+
"begin": "^\\s*((?:export )?use)\\s+([\\w\\-]+|\"[\\w\\- ]+\"|'[\\w\\- ]+')\\s*\\[",
359+
"beginCaptures": {
360+
"1": { "name": "entity.name.function.nushell" },
361+
"2": { "name": "entity.name.namespace.nushell" }
362+
},
363+
"end": "(\\])\\s*;?\\s*$",
364+
"endCaptures": {
365+
"1": { "name": "meta.brace.square.end.nushell" }
366+
},
367+
"patterns": [
368+
{
369+
"match" : "([\\w\\-]+|\"[\\w\\- ]+\"|'[\\w\\- ]+'|\\*),?",
370+
"captures": {
371+
"1": { "name": "keyword.other.nushell" }
372+
}
373+
},
374+
{
375+
"include": "#comment"
376+
}
377+
]
378+
},
379+
{
380+
"match": "(?<path>(?:/|\\\\|~[\\/\\\\]|\\.\\.?[\\/\\\\])?(?:[^\\/\\\\]+[\\/\\\\])*[\\w\\- ]+(?:\\.nu)?){0}^\\s*((?:export )?use)\\s+(\"\\g<path>\"|'\\g<path>\\'|(?![\"'])\\g<path>)(?:\\s+([\\w\\-]+|\"[\\w\\- ]+\"|'[^']+'|\\*))?\\s*;?$",
381+
"captures": {
382+
"2": { "name": "entity.name.function.nushell" },
383+
"3": {
384+
"name": "string.bare.nushell",
385+
"patterns": [
386+
{
387+
"match": "([\\w\\- ]+)(?:\\.nu)?(?=$|\"|')",
388+
"captures": {
389+
"1": {"name": "entity.name.namespace.nushell"}
390+
}
391+
}
392+
]
393+
},
394+
"4": { "name": "keyword.other.nushell" }
395+
}
396+
},
397+
{
398+
"begin": "(?<path>(?:/|\\\\|~[\\/\\\\]|\\.\\.?[\\/\\\\])?(?:[^\\/\\\\]+[\\/\\\\])*[\\w\\- ]+(?:\\.nu)?){0}^\\s*((?:export )?use)\\s+(\"\\g<path>\"|'\\g<path>\\'|(?![\"'])\\g<path>)\\s+\\[",
399+
"beginCaptures": {
400+
"2": { "name": "entity.name.function.nushell" },
401+
"3": {
402+
"name": "string.bare.nushell",
403+
"patterns": [
404+
{
405+
"match": "([\\w\\- ]+)(?:\\.nu)?(?=$|\"|')",
406+
"captures": {
407+
"1": {"name": "entity.name.namespace.nushell"}
408+
}
409+
}
410+
]
411+
}
412+
},
413+
"end": "(\\])\\s*;?\\s*$",
414+
"endCaptures": {
415+
"1": { "name": "meta.brace.square.end.nushell" }
416+
},
417+
"patterns": [
418+
{
419+
"match" : "([\\w\\-]+|\"[\\w\\- ]+\"|'[\\w\\- ]+'|\\*),?",
420+
"captures": {
421+
"0": { "name": "keyword.other.nushell" }
422+
}
423+
},
424+
{
425+
"include": "#comment"
426+
}
427+
]
428+
},
429+
{
430+
"match": "^\\s*(?:export )?use",
431+
"captures": {
432+
"0": { "name": "entity.name.function.nushell" }
433+
}
434+
}
435+
]
354436
},
355437
"for-loop": {
356438
"begin": "(for)\\s+(\\$?\\w+)\\s+(in)\\s+(.+)\\s*(\\{)",

0 commit comments

Comments
 (0)