%YAML 1.2
---
name: Nim
file_extensions: [nim, nims, nimble]
scope: source.nim
version: 2
variables:
letter_bare: 'A-Za-z\x80-\x{10FFFF}&&[^{{UNICODE_OPR}}]'
letter: '[{{letter_bare}}]'
ident: '{{letter}}(?:_?[\d{{letter_bare}}])*|_'
symbol: '{{ident}}|`[^;,\n`]+`'
symbol_lookahead: '(?={{letter}}|\(|`|_\b)'
pragma_start: '\{\.(?!\.})'
string_escape_chars: '\\(?:[ABCEFLNPRTVabceflnprtv"''\\]|\d+|[Xx]\h{2}|[Uu](?:\h{4}|\{\h+}))'
UNICODE_OPR: '∙∘×★⊗⊘⊙⊛⊠⊡∩∧⊓±⊕⊖⊞⊟∪∨⊔'
OPR: '-=\+\*/<>@\$~&%\|!\?\^\.:\\{{UNICODE_OPR}}'
format_spec: '=?(?: *:[^}]*)?'
disallowed_keyws: '(?x:as|asm|and|bind|break|concept|const|continue|converter
|defer|discard|distinct|div|elif|else|end|except|export|finally|from|import
|include|interface|is(?:not)?|let|macro|method|mixin|mod|(?:not)?in|of
|raise|sh[lr]|template|using|while|yield|x?or)'
keyws: '(?x:{{disallowed_keyws}}|addr|block|case|cast|do|enum|for|func|if|iterator
|object|out|proc|ptr|ref|return|static|try|tuple|type|var|when)\b'
generic_builtin_types: '(?x:out|ptr|ref|array|cstring[Aa]rray|iterable|lent
|open[Aa]rray|owned|range|se[qt]|sink|static|type(?:desc)?|varargs)'
builtin_types: '(?x:any|array|auto|bool|byte
|c(?:double|float|u?(?:long(?:long)?|char|int|short)|longdouble|schar
|size(?:_t)?|string(?:[Aa]rray)?)
|char|float(?:32|64)?|iterable|lent|open[Aa]rray|owned|pointer|ptr|range|ref|se[qt]
|sink|static|string|typed?|typedesc|u?int(?:8|16|32|64)?|untyped|varargs|void)'
builtin_constants: '(?x:appType|Compile(?:Date|Time)|cpuEndian
|host(?:CPU|OS)
|isMainModule|NaN|(?:Neg)?Inf|Nim(?:Major|Minor|Patch|Version)|nimvm|off|on
|Quit(?:Failure|Success))'
float_suffix: '''(?:{{ident}})|(?:[Ff](?:32|64)|[Dd])'
int_suffix: '''(?:{{ident}})|(?:[IUiu](?:8|16|32|64)|[Uu])'
contexts:
main:
- include: type-defs
- include: const-defs
- include: var-let-using-defs
- include: pragmas
- include: brackets
- include: punctuations
- include: doc-comments
- include: comments
- include: for-stmts
- include: asm-stmts
- include: routines
- include: fmt-strs
- include: operators
- include: literals
- include: do-stmts
- include: keywords
- include: calls
- include: types
- include: builtins
- include: generic-symbols
else-pop:
- match: (?=\S)
pop: true
generic-symbols:
- match: '[A-Z](_?[\d{{letter_bare}}&&[^a-z]])+\b'
scope: support.constant.nim
- match: '[A-Z](_?[\d{{letter_bare}}])+\b'
scope: support.type.nim
- match: '{{symbol}}'
types:
- match: \btuple(?=\[)
scope: storage.type.primitive.nim
push: generic-param-list
- match: '\b(?=(?:{{ident}})\[)(?:({{generic_builtin_types}})|([A-Z][\d{{letter_bare}}]+))(\[)'
captures:
1: storage.type.primitive.nim
2: support.type.nim
3: meta.generic.nim punctuation.section.generic.begin.nim
push:
- meta_content_scope: meta.generic.nim
- match: ']'
scope: meta.generic.nim punctuation.section.generic.end.nim
pop: true
- include: main
- match: \b(?:out|tuple|ref|ptr)\b
scope: storage.type.primitive.nim
brackets:
- include: square-brackets
- match: '\{'
scope: punctuation.section.braces.begin.nim
push:
- meta_scope: meta.braces.nim
- match: '}'
scope: punctuation.section.braces.end.nim
pop: true
- include: main
- match: '\('
scope: punctuation.section.parens.begin.nim
push:
- meta_scope: meta.parens.nim
- match: '\)'
scope: punctuation.section.parens.end.nim
pop: true
- include: main
square-brackets:
- match: '\['
scope: punctuation.section.brackets.begin.nim
push:
- meta_scope: meta.brackets.nim
- match: ']'
scope: punctuation.section.brackets.end.nim
pop: true
- include: main
builtins:
- match: \bresult\b
scope: variable.language.nim
- match: \b(?:{{builtin_types}})\b
scope: storage.type.primitive.nim
- match: \b(?:{{builtin_constants}})\b
scope: support.constant.builtin.nim
type-defs:
- match: '^ *(type) +(?:(?:{{symbol}}) *(\.))?({{symbol}})(?: *(\*))?'
captures:
1: keyword.declaration.type.nim
2: punctuation.accessor.dot.nim
3: entity.name.type.nim
4: storage.modifier.nim
push: generic-param-list
- match: ^type\b
scope: keyword.declaration.type.nim
push:
- match: ^(?! |$)
pop: true
- match: '^ (?:(?:{{symbol}}) *(\.))?({{symbol}})(?: *(\*))?'
captures:
1: punctuation.accessor.dot.nim
2: entity.name.type.nim
3: storage.modifier.nim
push: generic-param-list
- include: main
const-defs:
- match: \b(const) +{{symbol_lookahead}}
captures:
1: storage.modifier.nim keyword.declaration.constant.nim
push: const-name
- match: ^const\b
scope: storage.modifier.nim keyword.declaration.constant.nim
push:
- match: ^(?! |$)
pop: true
- match: '^ {{symbol_lookahead}}'
push: const-name
- include: main
const-name:
- match: '({{keyws}})(?: *(\*))?'
captures:
1: invalid.illegal.nim
2: storage.modifier.nim
pop: true
- match: '({{symbol}})(?: *(\*))?'
captures:
1: entity.name.constant.nim
2: storage.modifier.nim
set:
- include: comments
- include: pragmas
- match: (:)|(=)
captures:
1: punctuation.separator.annotation.nim
2: keyword.operator.assignment.nim
pop: true
- match: ','
scope: invalid.illegal.nim
pop: true
- include: else-pop
- match: '\('
scope: punctuation.section.parens.begin.nim
set:
- match: '\)'
scope: punctuation.section.parens.end.nim
set:
- include: comments
- match: ':'
scope: invalid.illegal.nim
pop: true
- include: else-pop
- match: '({{keyws}})(?: *(\*))?'
captures:
1: invalid.illegal.nim
2: storage.modifier.nim
- match: '({{symbol}})(?: *(\*))?'
captures:
1: entity.name.constant.nim
2: storage.modifier.nim
- match: ','
scope: punctuation.separator.nim
- include: pragmas
- include: doc-comments
- include: comments
- include: else-pop
var-let-using-defs:
- match: (?:^|(;)) *(var|let|using) +{{symbol_lookahead}}
captures:
1: punctuation.terminator.nim
2: storage.modifier.nim keyword.declaration.variable.nim
push: var-name
- match: ^(?:var|let|using)\b
scope: storage.modifier.nim keyword.declaration.variable.nim
push:
- match: ^(?! |$)
pop: true
- match: '^ {{symbol_lookahead}}'
push: var-name
- include: main
var-name:
- match: '\('
scope: punctuation.section.parens.begin.nim
set:
- match: '\)'
scope: punctuation.section.parens.end.nim
set:
- include: comments
- match: ':'
scope: invalid.illegal.nim
pop: true
- include: else-pop
- include: var-name-0
- match: '(?!{{keyws}})({{symbol}})(?: *(\*))?'
captures:
1: entity.name.variable.nim
2: storage.modifier.nim
push:
- match: ','
scope: punctuation.separator.nim
set:
- include: doc-comments
- include: comments
- match: (?=[^ ])
pop: true
- include: pragmas
- include: comments
- match: '{{symbol}}'
scope: invalid.illegal.nim
pop: true
- match: (?=[^ ])
pop: true
- match: ':'
scope: punctuation.separator.annotation.nim
pop: true
- match: (?=[^ ])
pop: true
var-name-0:
- match: '(?!{{keyws}})({{symbol}})(?: *(\*))?'
captures:
1: entity.name.variable.nim
2: storage.modifier.nim
push:
- match: ','
scope: punctuation.separator.nim
set:
- include: doc-comments
- include: comments
- include: else-pop
- include: pragmas
- include: comments
- match: '{{symbol}}'
scope: invalid.illegal.nim
pop: true
- include: else-pop
- match: ':'
scope: punctuation.separator.annotation.nim
pop: true
- include: else-pop
do-stmts:
- match: \bdo\b
scope: storage.type.function.nim keyword.declaration.function.nim
push: [do-stmts-1, do-stmts-0]
do-stmts-0:
- match: '\('
scope: meta.function.parameters.nim punctuation.section.parameters.begin.nim
set:
- meta_content_scope: meta.function.parameters.nim
- match: '{{symbol}}'
scope: meta.function.parameters.nim variable.parameter.nim
set: [param-list, decl-col-eq-1]
- match: '\)'
scope: meta.function.parameters.nim punctuation.section.parameters.end.nim
pop: true
- include: else-pop
- include: else-pop
do-stmts-1:
- match: '->'
scope: punctuation.separator.annotation.return.nim
- include: else-pop
calls:
- match: '(?x:
(?=(?:(?!(?:out|ptr|ref|tuple)\b){{symbol}})
(?:\[.*])?
(?:
\(
|"
|[ ]+
(?:
[_\d"''`\[\(]
|(?!\.|(?:\* *)?[:=]|=[^=])[{{OPR}}]+[^{{OPR}}\s]
|(?!{{disallowed_keyws}}\b){{letter}}
|\{(?!\.)
)
)
)
)'
push: [args-list, routine-name]
routine-name:
- meta_content_scope: meta.function-call.nim variable.function.nim
- include: builtins
- include: generic-symbols
- match: ''
set: generic
generic:
- match: '\[:?'
scope: punctuation.section.generic.begin.nim
set:
- meta_scope: meta.function-call.nim meta.generic.nim
- match: ']'
scope: punctuation.section.generic.end.nim
pop: true
- include: main
- match: ''
pop: true
args-list:
- match: '\('
scope: punctuation.section.arguments.begin.nim
set:
- meta_scope: meta.function-call.arguments.nim
- match: '\)'
scope: punctuation.section.arguments.end.nim
pop: true
- match: '(?x:
(?=
(?:{{symbol}})
[ ]*
[:=](?![{{OPR}}])
)
(?!{{keyws}})({{symbol}})
(?:[ ]*(:))?
|
(?=\S)
)'
captures:
1: variable.parameter.nim
2: punctuation.separator.key-value.nim
push:
- match: (?=\))
pop: true
- match: ','
scope: punctuation.separator.nim
set:
- include: comments
- include: else-pop
- include: main
- match: '"""'
scope: meta.string.nim string.quoted.double.block.nim punctuation.definition.string.begin.nim
set: triplestr_lit_inner
- match: '"'
scope: meta.string.nim string.quoted.double.nim punctuation.definition.string.begin.nim
set: rstr_lit_inner
- match: ''
pop: true
punctuations:
- match: ';'
scope: punctuation.terminator.statement.nim
- match: ','
scope: punctuation.separator.nim
- match: ':'
scope: punctuation.section.block.begin.nim
- match: \.(?![{{OPR}}])
scope: punctuation.accessor.dot.nim
- match: '(\*) *(:|(?=,|#|\{\.))'
captures:
1: storage.modifier.nim
2: punctuation.separator.annotation.nim
- match: '\)|]|}'
scope: invalid.illegal.nim
doc-comments:
- include: block-doc-comment
- include: line-doc-comment
comments:
- include: block-comment
- include: line-comment
comment:
- include: comments
- include: else-pop
no-doc-comment:
- match: '(?=##)'
pop: true
- include: comment
line-comment:
- match: '(#)(?: *(TODO|todo))?'
captures:
1: punctuation.definition.comment.nim
2: invalid.deprecated.nim
push:
- meta_scope: comment.line.number-sign.nim
- match: '$\n?'
pop: true
block-comment:
- match: '#\['
scope: comment.block.nim punctuation.definition.comment.begin.nim
push:
- meta_content_scope: comment.block.nim
- match: '\]#'
scope: comment.block.nim punctuation.definition.comment.end.nim
pop: true
- include: block-comment
line-doc-comment:
- match: '##'
scope: punctuation.definition.comment.nim
push:
- meta_scope: comment.line.documentation.nim
- match: '$\n?'
pop: true
block-doc-comment:
- match: '##\['
scope: punctuation.definition.comment.begin.nim
push:
- meta_scope: comment.block.documentation.nim
- match: ']##'
scope: punctuation.definition.comment.end.nim
pop: true
- include: block-doc-comment
str_lits:
- include: triplestr_lit
- include: rstr_lit
- include: str_lit
str_lit:
- match: '"'
scope: punctuation.definition.string.begin.nim
push: str_lit_inner
str_lit_inner:
- meta_scope: meta.string.nim string.quoted.double.nim
- match: '{{string_escape_chars}}'
scope: constant.character.escape.nim
- match: \\
scope: invalid.illegal.lone-escape.nim
- match: '"'
scope: punctuation.definition.string.end.nim
pop: true
- match: \n
scope: invalid.illegal.nim
pop: true
rstr_lit:
- match: '([Rr])(")'
captures:
0: meta.string.nim
1: storage.type.string.nim
2: string.quoted.double.nim punctuation.definition.string.begin.nim
push: rstr_lit_inner
rstr_lit_inner:
- meta_content_scope: meta.string.nim string.quoted.double.nim
- match: '""'
scope: constant.character.escape.double-quote.nim
- match: '"'
scope: meta.string.nim string.quoted.double.nim punctuation.definition.string.end.nim
pop: true
- match: '\n'
scope: meta.string.nim string.quoted.double.nim invalid.illegal.unclosed-string.nim
pop: true
triplestr_lit:
- match: '([Rr])?(""")'
captures:
0: meta.string.nim
1: storage.type.string.nim
2: string.quoted.double.block.nim punctuation.definition.string.begin.nim
push: triplestr_lit_inner
triplestr_lit_inner:
- meta_content_scope: meta.string.nim string.quoted.double.block.nim
- match: '"""(?!")'
scope: meta.string.nim string.quoted.double.block.nim punctuation.definition.string.end.nim
pop: true
fmt-strs:
- match: '(?:(fmt)|(&))(""")'
captures:
1: meta.function-call.nim variable.function.nim
2: keyword.operator.nim
3: meta.string.interpolated.nim string.quoted.double.block.nim punctuation.definition.string.begin.nim
push:
- meta_content_scope: meta.string.interpolated.nim string.quoted.double.block.nim
- match: '\{\{|\}\}'
scope: constant.character.escape.nim
- match: '}'
scope: invalid.illegal.nim
- match: '{'
scope: punctuation.section.interpolation.begin.nim
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.nim
- match: '(?="""[^"])'
pop: true
- match: '({{format_spec}}) *(})'
captures:
1: constant.other.format-spec.nim
2: punctuation.section.interpolation.end.nim
pop: true
- include: main
with_prototype:
- match: '\\\{|\\\}'
scope: constant.character.escape.nim
- match: '{'
scope: invalid.illegal.nim
- match: '"""(?!")'
scope: meta.string.interpolated.nim string.quoted.double.block.nim punctuation.definition.string.end.nim
pop: true
- match: (fmt)(")
captures:
1: meta.function-call.nim variable.function.nim
2: meta.string.interpolated.nim string.quoted.double.nim punctuation.definition.string.begin.nim
push:
- meta_content_scope: meta.string.interpolated.nim string.quoted.double.nim
- match: '\{\{|\}\}'
scope: constant.character.escape.nim
- match: '}'
scope: invalid.illegal.nim
- match: '{'
scope: punctuation.section.interpolation.begin.nim
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.nim
- match: \n
scope: invalid.illegal.nim
pop: true
- match: '(?=")'
pop: true
- match: '({{format_spec}}) *(})'
captures:
1: constant.other.format-spec.nim
2: punctuation.section.interpolation.end.nim
pop: true
- include: main
with_prototype:
- match: '\\\{|\\\}'
scope: constant.character.escape.nim
- match: '{'
scope: invalid.illegal.nim
- match: '""'
scope: meta.string.interpolated.nim string.quoted.double.nim constant.character.escape.double-quotes.nim
- match: \n
scope: invalid.illegal.nim
pop: true
- match: '"'
scope: meta.string.interpolated.nim string.quoted.double.nim punctuation.definition.string.end.nim
pop: true
- match: (&)(")
captures:
1: meta.string.interpolated.nim keyword.operator.nim
2: meta.string.interpolated.nim string.quoted.double.nim punctuation.definition.string.begin.nim
push:
- meta_content_scope: meta.string.interpolated.nim string.quoted.double.nim
- match: '\{\{|\}\}'
scope: constant.character.escape.nim
- match: '}'
scope: invalid.illegal.nim
- match: '{'
scope: punctuation.section.interpolation.begin.nim
push:
- clear_scopes: 1
- meta_scope: meta.interpolation.nim
- match: '{{string_escape_chars}}'
scope: constant.character.escape.nim
- match: \\
scope: invalid.illegal.lone-escape.nim
- match: \n
scope: invalid.illegal.nim
pop: true
- match: '(?=")'
pop: true
- match: '({{format_spec}}) *(})'
captures:
1: constant.other.format-spec.nim
2: punctuation.section.interpolation.end.nim
pop: true
- include: main
with_prototype:
- match: '\\\{|\\\}'
scope: constant.character.escape.nim
- match: '{'
scope: invalid.illegal.nim
- match: '{{string_escape_chars}}'
scope: constant.character.escape.nim
- match: \\
scope: invalid.illegal.lone-escape.nim
- match: \n
scope: invalid.illegal.nim
pop: true
- match: '"'
scope: meta.string.interpolated.nim string.quoted.double.nim punctuation.definition.string.end.nim
pop: true
interpolation:
- match: (?=`)
push:
- clear_scopes: 1
- match: '(`)(?:{{ident}})?(`)'
captures:
0: meta.interpolation.nim
1: punctuation.section.interpolation.begin.nim
2: punctuation.section.interpolation.end.nim
pop: true
- match: ''
pop: true
numbers:
- match: '(?x:
\b(\d(?:_?\d)*)
(?:
(?:
((\.)\d(?:_?\d)*)
([Ee][-+]?\d(?:_?\d)*)?
|([Ee][-+]?\d(?:_?\d)*)
)
({{float_suffix}})?
|({{float_suffix}})
)
)'
captures:
0: meta.number.float.decimal.nim
1: constant.numeric.value.nim
2: constant.numeric.value.nim
3: punctuation.separator.decimal.nim
4: constant.numeric.value.exponent.nim
5: constant.numeric.value.exponent.nim
6: constant.numeric.suffix.nim
7: constant.numeric.suffix.nim
- match: '(?x:
\b(0[Xx])
(\h(?:_?\h)*)
(''(?:{{ident}})|[Ff](?:32|64))
)'
captures:
0: meta.number.float.hexadecimal.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(0o)
([0-7](?:_?[0-7])*)
({{float_suffix}})
)'
captures:
0: meta.number.float.octal.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(0[Bb])
([01](?:_?[01])*)
({{float_suffix}})
)'
captures:
0: meta.number.float.binary.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(0[Xx])
(\h(?:_?\h)*)
({{int_suffix}})?
)'
captures:
0: meta.number.integer.hexadecimal.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(0o)
([0-7](?:_?[0-7])*)
({{int_suffix}})?
)'
captures:
0: meta.number.integer.octal.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(0[Bb])
([01](?:_?[01])*)
({{int_suffix}})?
)'
captures:
0: meta.number.integer.binary.nim
1: constant.numeric.base.nim
2: constant.numeric.value.nim
3: constant.numeric.suffix.nim
- match: '(?x:
\b(\d(?:_?\d)*)
({{int_suffix}})?
)'
captures:
0: meta.number.integer.decimal.nim
1: constant.numeric.value.nim
2: constant.numeric.suffix.nim
characters:
- match: '''(?:[^\\'']|(\\(?:[ABCEFLNRTVabceflnrtv"''\\]|\d+|[Xx]\h{2})))'''
captures:
0: constant.character.nim
1: constant.character.escape.nim
- match: '''[^'']+'''
scope: invalid.illegal.nim
language-constants:
- match: '\b(?:true|false|nil)\b'
scope: constant.language.nim
literals:
- include: str_lits
- include: numbers
- include: characters
- include: language-constants
keywords:
- match: '\b(?:addr|cast)\b'
scope: keyword.operator.word.nim
- match: \bdiscard +"""
scope: punctuation.definition.comment.begin.nim
push:
- meta_scope: comment.block.nim
- match: '"""(?!")'
scope: punctuation.definition.comment.end.nim
pop: true
- match: '\b(?:distinct|discard)\b'
scope: keyword.other.nim
- match: '\b(?:asm|end|break|continue|raise|return|yield)\b'
scope: keyword.control.flow.nim
- match: \b(?:concept|enum|interface)\b
scope: storage.type.nim
- match: '\b(object)\b(?: *(of)\b)?'
captures:
1: storage.type.nim
2: keyword.other.nim
- match: '\bwhile\b'
scope: keyword.control.loop.while.nim
- match: '\bcase\b'
scope: keyword.control.conditional.switch.nim
- match: '^ *(of)\b'
scope: keyword.control.conditional.case.nim
- match: '\bif\b'
scope: keyword.control.conditional.if.nim
- match: '\bwhen\b'
scope: keyword.control.conditional.when.nim
- match: '\belif\b'
scope: keyword.control.conditional.elseif.nim
- match: '\b(else)\b(?: *(:))?'
captures:
1: keyword.control.conditional.else.nim
2: punctuation.section.block.conditional.else.nim
- match: '\b(try)\b(?: *(:))?'
captures:
1: keyword.control.exception.try.nim
2: punctuation.section.block.exception.nim
- match: '\b(finally)\b(?: *(:))?'
captures:
1: keyword.control.exception.finally.nim
2: punctuation.section.block.exception.finally.nim
- match: '\b(defer)\b(?: *(:))?'
captures:
1: keyword.control.flow.defer.nim
2: punctuation.section.block.begin.nim
- match: '\b(block)\b(?:(?: *(?:{{symbol}}))? *(:))?'
captures:
1: keyword.declaration.block.nim
2: punctuation.section.block.begin.nim
- match: '\b(?:as|(?:ex|im)port|include|bind|mixin|from|except)\b'
scope: keyword.control.nim
- match: '\b(?:const|let|using)\b'
scope: storage.modifier.nim keyword.declaration.nim
- match: \bvar\b
scope: storage.modifier.nim
asm-stmts:
- match: \basm\b
scope: keyword.control.flow.nim
push: [asm-stmt-1, pragma-0]
asm-stmt-1:
- match: '([Rr])?(""")'
captures:
0: meta.string.nim
1: storage.type.string.nim
2: string.quoted.double.block.nim punctuation.definition.string.begin.nim
set:
- meta_content_scope: meta.string.nim string.quoted.double.block.nim
- include: triplestr_lit_inner
- include: interpolation
- match: '([Rr])(")'
captures:
0: meta.string.nim
1: storage.type.string.nim
2: string.quoted.double.nim punctuation.definition.string.begin.nim
set:
- meta_content_scope: meta.string.nim string.quoted.double.nim
- include: rstr_lit_inner
- include: interpolation
- match: '"'
scope: punctuation.definition.string.begin.nim
set:
- meta_scope: meta.string.nim string.quoted.double.nim
- include: str_lit_inner
- include: interpolation
- include: else-pop
routines:
- match: '(?:proc|func|method|template|macro|iterator|converter)\b'
scope: storage.type.function.nim keyword.declaration.function.nim
push: [routine-0, no-doc-comment]
routine-0:
- meta_scope: meta.function.nim
- match: '{{symbol_lookahead}}'
set: [routine-2, routine-1]
- match: (?=\S)
set: routine-3
routine-1:
- meta_content_scope: entity.name.function.nim
- match: '\b(?:addr|type|static)\b'
scope: 'keyword.nim'
- match: '{{keyws}}'
scope: invalid.illegal.nim
- match: '{{symbol}}'
- match: ' *(\*)'
captures:
1: storage.modifier.nim
pop: true
- match: ''
pop: true
routine-2:
- meta_content_scope: meta.function.nim
- match: '\{(?!\.)'
scope: punctuation.definition.pattern.begin.nim
set:
- meta_scope: meta.function.pattern.nim
- match: '}'
scope: punctuation.definition.pattern.end.nim
set: routine-3
- include: main
- include: routine-3
routine-3:
- match: '\['
scope: punctuation.section.generic.begin.nim
set: [routine-4, generic-param-list-0]
- include: routine-4
routine-4:
- match: '\('
scope: meta.function.parameters.nim punctuation.section.parameters.begin.nim
set:
- meta_content_scope: meta.function.parameters.nim
- match: '{{keyws}}'
scope: invalid.illegal.nim
pop: true
- match: '{{symbol}}'
scope: meta.function.parameters.nim variable.parameter.nim
set: [routine-5, param-list, decl-col-eq-1]
- match: '\)'
scope: meta.function.parameters.nim punctuation.section.parameters.end.nim
set: routine-5
- match: '(?=\S)'
set: routine-5
- include: routine-5
routine-5:
- meta_content_scope: meta.function.nim
- match: ':'
scope: meta.function.nim punctuation.separator.annotation.return.nim
pop: true
- include: else-pop
generic-param-list:
- match: '\['
scope: punctuation.section.generic.begin.nim
set: generic-param-list-0
- include: else-pop
generic-param-list-0:
- meta_scope: meta.generic.nim
- match: '{{keyws}}'
scope: invalid.illegal.nim
- match: '{{symbol}}'
scope: variable.parameter.nim
- match: '[,;]'
scope: punctuation.separator.nim
- match: '(:)|(=)'
captures:
1: punctuation.separator.annotation
2: keyword.operator.assignment.nim
push: generic-param-list-1
- match: '\]'
scope: punctuation.section.generic.end.nim
pop: true
- include: comments
- include: else-pop
generic-param-list-1:
- match: '[,;]'
scope: punctuation.separator.nim
pop: true
- match: '(?=\])'
pop: true
- include: main
param-list:
- meta_content_scope: meta.function.parameters.nim
- clear_scopes: 1
- match: '[,;]'
scope: punctuation.separator.parameters.nim
push: [decl-col-eq-0, comment]
- match: '\)'
scope: meta.function.parameters.nim punctuation.section.parameters.end.nim
pop: true
- include: else-pop
decl-col-eq-0:
- match: '{{keyws}}'
scope: invalid.illegal.nim
pop: true
- match: '{{symbol}}'
scope: variable.parameter.nim
set: decl-col-eq-1
- include: else-pop
decl-col-eq-1:
- match: '{{pragma_start}}'
scope: punctuation.definition.annotation.begin.nim
set: [decl-col-eq-2, pragma-1]
- match: ','
scope: punctuation.separator.parameters.nim
set: [decl-col-eq-2, decl-col-eq-3, comment]
- match: ':'
scope: punctuation.separator.annotation.parameter.nim
set: decl-col-eq-4
- match: '='
scope: keyword.operator.assignment.nim
set: decl-col-eq-4
- include: else-pop
decl-col-eq-2:
- match: ','
scope: punctuation.separator.parameters.nim
push: [decl-col-eq-3, comment]
- match: ':'
scope: punctuation.separator.annotation.parameter.nim
set: decl-col-eq-4
- match: '='
scope: keyword.operator.assignment.nim
set: decl-col-eq-4
- include: else-pop
decl-col-eq-3:
- match: '{{keyws}}'
scope: invalid.illegal.nim
pop: true
- match: '{{symbol}}'
scope: variable.parameter.nim
set: pragma-0
- match: '\S'
scope: invalid.illegal.nim
pop: true
decl-col-eq-4:
- match: '(?=[,;\)])'
pop: true
- include: main
pragmas:
- match: '{{pragma_start}}'
scope: punctuation.definition.annotation.begin.nim
push: pragma-1
pragma-0:
- include: pragmas
- include: else-pop
pragma-1:
- meta_scope: meta.annotation.nim
- match: '\.?}'
scope: punctuation.definition.annotation.end.nim
pop: true
- include: calls
- match: '{{symbol}}'
scope: entity.other.attribute-name.pragma.nim
- include: square-brackets
- match: (?=\S)
push: pragma-2
pragma-2:
- match: ':'
scope: punctuation.separator.key-value.nim
set:
- match: '(?=\.?})'
pop: true
- match: ','
scope: punctuation.separator.nim
pop: true
- include: main
- match: ','
scope: punctuation.separator.nim
pop: true
- include: else-pop
for-stmts:
- match: '\bfor\b'
scope: keyword.control.loop.for.nim
push: for-stmt-0
for-stmt-0:
- match: \(
scope: punctuation.section.parens.begin.nim
set:
- match: \)
scope: punctuation.section.parens.end.nim
set:
- match: '\bin\b'
scope: keyword.control.loop.for.in.nim
pop: true
- include: else-pop
- include: for-stmt-1
- include: else-pop
- match: '\bin\b'
scope: keyword.control.loop.for.in.nim
pop: true
- include: for-stmt-1
- match: '(?=[^ ])'
pop: true
for-stmt-1:
- match: ','
scope: punctuation.separator.nim
- match: '{{symbol}}'
- include: pragmas
- include: comments
operators:
- match: '\b(?:and|not|x?or)\b'
scope: keyword.operator.logical.nim
- match: ^of\b
scope: keyword.control.conditional.case.nim
- match: '\b(?:of|(?:not)?in|is(?:not)?)\b'
scope: keyword.operator.word.nim
- match: \bsh[lr]\b
scope: keyword.operator.bitwise.nim
- match: '\b(?:div|mod)\b'
scope: keyword.operator.arithmetic.nim
- match: '==|<=?|>=?|!='
scope: keyword.operator.comparison.nim
- match: '(?:[[{{OPR}}]&&[^<>!=~?]][{{OPR}}]*)?=(?![{{OPR}}])'
scope: keyword.operator.assignment.nim
- match: '[{{OPR}}]+'
scope: keyword.operator.nim