Skip to content

Commit

Permalink
Updated syntax highlighting for nim
Browse files Browse the repository at this point in the history
  • Loading branch information
Nimaoth committed Jul 19, 2024
1 parent a953824 commit 89df420
Show file tree
Hide file tree
Showing 2 changed files with 197 additions and 57 deletions.
231 changes: 174 additions & 57 deletions languages/nim/queries/highlights.scm
Original file line number Diff line number Diff line change
@@ -1,73 +1,190 @@
((ident) @support.type.nim
(#match? @support.type.nim "^[A-Z].*$"))
(typeDesc (primaryTypeDesc (symbol (ident) @storage.type)))
((ident) @storage.type
(#match? @storage.type "^(int|int8|int16|int32|int64|uint|uint8|uint16|uint32|uint64|float|float32|float64|bool|string|char|typed|untyped|openArray|seq|array|set)$"))
((ident) @keyword
(#match? @keyword "^(end|echo|declared|low|high|ord|async|await|if|else|elif|some|none|void|return|for|try|except|when|let|var|const)$"))

(routine (keyw) (symbol (ident) @variable.function))

"=" @punctuation
":" @punctuation
"." @punctuation
"," @punctuation
";" @punctuation
"(" @punctuation
")" @punctuation
"[" @punctuation
"]" @punctuation
"{" @punctuation
"}" @punctuation

(primary
(primarySuffix) @variable.function
.
(primarySuffix (functionCall))
)
(primary
.
(_) @variable.function
.
(primarySuffix (functionCall))
)

(ident) @variable
; SPDX-FileCopyrightText: 2023 Leorize <[email protected]>
; SPDX-License-Identifier: MPL-2.0

[
(str_lit)
(char_lit)
(rstr_lit)
(triplestr_lit)
(generalized_str_lit)
(interpolated_str_lit)
] @string
; Punctuations
[ "." ";" "," ":" ] @punctuation.delimiter
[ "(" ")" "[" "]" "{" "}" "{." ".}" ] @punctuation.bracket

[
(int_lit)
(float_lit)
(float_suffix)
(int_suffix)
] @constant.numeric
; Operator by default, but could be overriden
[ "=" ] @operator

; Special
(blank_identifier) @variable.builtin

; Calls
(call
function: [
(identifier) @function.call
(dot_expression
right: (identifier) @function.call)
])
(generalized_string
function: [
(identifier) @function.call
(dot_expression
right: (identifier) @function.call)
])

(customNumericLitSuffix) @support.type
; Declarations
(exported_symbol "*" @type.qualifier)
(_ "=" @punctuation.delimiter [body: (_) value: (_)])
(proc_declaration name: (_) @function)
(func_declaration name: (_) @function)
(converter_declaration name: (_) @function)
(method_declaration name: (_) @method)
(template_declaration name: (_) @function.macro)
(macro_declaration name: (_) @function.macro)
(symbol_declaration name: (_) @variable)
(parameter_declaration
(symbol_declaration_list
(symbol_declaration name: (_) @parameter)))
(_
[
type: [
(type_expression (identifier))
(type_expression (accent_quoted (identifier)))
] @type
return_type: [
(type_expression (identifier))
(type_expression (accent_quoted (identifier)))
] @type
])

; Exceptions
[
"true"
"false"
] @constant.numeric
"try"
"except"
"finally"
"raise"
] @exception

(except_branch values: (expression_list
[
(identifier) @type
(infix_expression
left: (identifier) @type
operator: "as"
right: (identifier) @variable)
]))

; Expressions
(dot_expression
right: (identifier) @field)

; Literal/comments
[
(comment)
(docComment)
(block_comment)
] @comment

(operator) @keyword.operator
[
(documentation_comment)
(block_documentation_comment)
] @comment.documentation

(keyw) @keyword
(interpreted_string_literal) @string
(long_string_literal) @string
(raw_string_literal) @string
(generalized_string) @string
(char_literal) @character
(escape_sequence) @string.escape
(integer_literal) @number
(float_literal) @float
(custom_numeric_literal) @number
(nil_literal) @constant.builtin

; Keyword
[
"nil"
"if"
"when"
"case"
"elif"
"else"
] @conditional

(of_branch "of" @conditional)

[
"import"
"include"
"export"
] @include

(import_from_statement "from" @include)
(except_clause "except" @include)

[
"for"
"while"
"continue"
"break"
] @repeat

(for "in" @repeat)

[
"macro"
"template"
"const"
"let"
"var"
"asm"
"bind"
"block"
"concept"
"defer"
"discard"
"distinct"
"do"
"enum"
"mixin"
"nil"
"object"
"out"
"ptr"
"ref"
"static"
"tuple"
"type"
] @keyword

[
"proc"
"func"
"method"
"converter"
"iterator"
] @keyword.function

[
"and"
"or"
"xor"
"not"
"div"
"mod"
"shl"
"shr"
"from"
"as"
"of"
"in"
"notin"
"is"
"isnot"
"cast"
] @keyword.operator

[
"return"
"yield"
] @keyword.return

; Operators
(infix_expression operator: _ @operator)
(prefix_expression operator: _ @operator)

((identifier) @type
(#match? @type "^[A-Z].*$"))
((identifier) @type
(#match? @type "^(openArray|typedesc)$"))
23 changes: 23 additions & 0 deletions themes/tokyo-night-color-theme.json
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,8 @@
"punctuation.definition.constant",
"constant.language",
"constant.numeric",
"number",
"float",
"support.constant"
// "constant.language.null",
// "constant.language.undefined",
Expand All @@ -509,6 +511,7 @@
"name": "String, Symbols",
"scope": [
"string",
"character",
"constant.other.symbol",
"constant.other.key",
"meta.attribute-selector"
Expand Down Expand Up @@ -607,7 +610,9 @@
"keyword.control.as",
"keyword.other",
"keyword.operator.bitwise.shift",
"type.qualifier",
"punctuation",
"operator",
"expression.embbeded.vue punctuation.definition.tag",
"text.html.twig meta.tag.inline.any.html",
"meta.tag.template.value.twig meta.function.arguments.twig",
Expand Down Expand Up @@ -638,6 +643,7 @@
"keyword.control.export",
"keyword.control.from",
"keyword.control.default",
"include",
"meta.import keyword.other"
],
"settings": {
Expand All @@ -649,6 +655,8 @@
"scope": [
"keyword",
"keyword.control",
"conditional",
"repeat",
"keyword.other.important"
],
"settings": {
Expand Down Expand Up @@ -728,6 +736,15 @@
"foreground": "#c0caf5"
}
},
{
"name": "Builtin Variables",
"scope": [
"variable.builtin"
],
"settings": {
"foreground": "#a4afdd"
}
},
{
"name": "Variable Array Key",
"scope": "meta.array.literal variable",
Expand All @@ -738,6 +755,7 @@
{
"name": "Object Key",
"scope": [
"field",
"meta.object-literal.key",
"entity.name.type.hcl",
"string.alias.graphql",
Expand Down Expand Up @@ -807,6 +825,9 @@
"name": "Function Definition",
"scope": [
"entity.name.function",
"function",
"method",
"function.call",
"variable.other.enummember",
"meta.function-call",
"meta.function-call entity.name.function",
Expand All @@ -823,6 +844,7 @@
"scope": [
"variable.parameter.function.language.special",
"variable.parameter",
"parameter",
"meta.function.parameters punctuation.definition.variable",
"meta.function.parameter variable"
],
Expand Down Expand Up @@ -869,6 +891,7 @@
"scope": [
"support.class",
"support.type",
"type",
"variable.other.readwrite.alias",
"support.orther.namespace.use.php",
"meta.use.php",
Expand Down

0 comments on commit 89df420

Please sign in to comment.