From b61c9c29f2670807d37a0cded8d989d419909ba5 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Mon, 20 Feb 2023 17:39:53 -0500 Subject: [PATCH 1/4] feat: add nasm language Co-authored-by: Grenier Celestin --- book/src/generated/lang-support.md | 1 + languages.toml | 13 +++ runtime/queries/nasm/highlights.scm | 130 +++++++++++++++++++++++++++ runtime/queries/nasm/injections.scm | 2 + runtime/queries/nasm/textobjects.scm | 15 ++++ 5 files changed, 161 insertions(+) create mode 100644 runtime/queries/nasm/highlights.scm create mode 100644 runtime/queries/nasm/injections.scm create mode 100644 runtime/queries/nasm/textobjects.scm diff --git a/book/src/generated/lang-support.md b/book/src/generated/lang-support.md index cdecb9b04832..c0e09397a0e4 100644 --- a/book/src/generated/lang-support.md +++ b/book/src/generated/lang-support.md @@ -85,6 +85,7 @@ | meson | ✓ | | ✓ | | | mint | | | | `mint` | | msbuild | ✓ | | ✓ | | +| nasm | ✓ | ✓ | | | | nickel | ✓ | | ✓ | `nls` | | nix | ✓ | | | `nil` | | nu | ✓ | | | | diff --git a/languages.toml b/languages.toml index 1caef6b2d99d..1fcc85864bd0 100644 --- a/languages.toml +++ b/languages.toml @@ -2204,3 +2204,16 @@ comment-token = "#" [[grammar]] name = "po" source = { git = "https://github.com/erasin/tree-sitter-po", rev = "417cee9abb2053ed26b19e7de972398f2da9b29e" } + +[[language]] +name = "nasm" +scope = "source.nasm" +file-types = ["asm", "s", "S", "nasm"] +injection-regex = "n?asm" +roots = [] +comment-token = ";" +indent = { tab-width = 8, unit = " " } + +[[grammar]] +name = "nasm" +source = { git = "https://github.com/naclsn/tree-sitter-nasm", rev = "a0db15db6fcfb1bf2cc8702500e55e558825c48b" } diff --git a/runtime/queries/nasm/highlights.scm b/runtime/queries/nasm/highlights.scm new file mode 100644 index 000000000000..2fef52d3e3d3 --- /dev/null +++ b/runtime/queries/nasm/highlights.scm @@ -0,0 +1,130 @@ +(comment) @comment +(ERROR) @error + +(label) @label + +[ + (preproc_expression) + (line_here_token) + (section_here_token) +] @variable.builtin +(preproc_expression + "]" @variable.builtin) +(preproc_expression + "}" @variable.builtin) + +(unary_expression + operator: _ @operator.unary) +(binary_expression + operator: _ @operator.binary) +(conditional_expression + "?" @operator + ":" @operator) + +[ + ":" + "," +] @punctuation.delimiter + +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +(instruction_prefix) @keyword +(actual_instruction + instruction: (word) @function) + +(call_syntax_expression + base: (word) @function) + +(size_hint) @type +(struc_declaration + name: (word) @type) +(struc_instance + name: (word) @type) + +(effective_address + hint: _ @type) +(effective_address + segment: _ @constant.builtin) + +(register) @constant.builtin + +(number_literal) @number.integer +(string_literal) @string +(float_literal) @number.float +(packed_bcd_literal) @number.integer + +((word) @constant + (#match? @constant "^[A-Z_][?A-Z_0-9]+$")) +((word) @constant.builtin + (#match? @constant.builtin "^__\\?[A-Z_a-z0-9]+\\?__$")) +(word) @variable + +(preproc_arg) @keyword + +[ + (preproc_def) + (preproc_function_def) + (preproc_undef) + (preproc_alias) + (preproc_multiline_macro) + (preproc_multiline_unmacro) + (preproc_if) + (preproc_rotate) + (preproc_rep_loop) + (preproc_include) + (preproc_pathsearch) + (preproc_depend) + (preproc_use) + (preproc_push) + (preproc_pop) + (preproc_repl) + (preproc_arg) + (preproc_stacksize) + (preproc_local) + (preproc_reporting) + (preproc_pragma) + (preproc_line) + (preproc_clear) +] @keyword +[ + (pseudo_instruction_dx) + (pseudo_instruction_resx) + (pseudo_instruction_incbin_command) + (pseudo_instruction_equ_command) + (pseudo_instruction_times_prefix) + (pseudo_instruction_alignx_macro) +] @keyword +[ + (assembl_directive_target) + (assembl_directive_defaults) + (assembl_directive_sections) + (assembl_directive_absolute) + (assembl_directive_symbols) + (assembl_directive_common) + (assembl_directive_symbolfixes) + (assembl_directive_cpu) + (assembl_directive_floathandling) + (assembl_directive_org) + (assembl_directive_sectalign) + + (assembl_directive_primitive_target) + (assembl_directive_primitive_defaults) + (assembl_directive_primitive_sections) + (assembl_directive_primitive_absolute) + (assembl_directive_primitive_symbols) + (assembl_directive_primitive_common) + (assembl_directive_primitive_symbolfixes) + (assembl_directive_primitive_cpu) + (assembl_directive_primitive_floathandling) + (assembl_directive_primitive_org) + (assembl_directive_primitive_sectalign) + (assembl_directive_primitive_warning) + (assembl_directive_primitive_map) +] @keyword diff --git a/runtime/queries/nasm/injections.scm b/runtime/queries/nasm/injections.scm new file mode 100644 index 000000000000..2f0e58eb6431 --- /dev/null +++ b/runtime/queries/nasm/injections.scm @@ -0,0 +1,2 @@ +((comment) @injection.content + (#set! injection.language "comment")) diff --git a/runtime/queries/nasm/textobjects.scm b/runtime/queries/nasm/textobjects.scm new file mode 100644 index 000000000000..ddfbad78cb30 --- /dev/null +++ b/runtime/queries/nasm/textobjects.scm @@ -0,0 +1,15 @@ +(preproc_multiline_macro + body: (body) @function.inside) @function.around +(struc_declaration + body: (struc_declaration_body) @class.inside) @class.around +(struc_instance + body: (struc_instance_body) @class.inside) @class.around + +(preproc_function_def_parameters + (word) @parameter.inside) +(call_syntax_arguments + (_) @parameter.inside) +(operand) @parameter.inside + +(comment) @comment.inside +(comment)+ @comment.around From eda2cc6590c783719871c95bde85e6589326bf69 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Tue, 21 Feb 2023 17:06:42 -0500 Subject: [PATCH 2/4] fix(queries/nasm): remove ERROR query --- runtime/queries/nasm/highlights.scm | 1 - 1 file changed, 1 deletion(-) diff --git a/runtime/queries/nasm/highlights.scm b/runtime/queries/nasm/highlights.scm index 2fef52d3e3d3..9c37177d8965 100644 --- a/runtime/queries/nasm/highlights.scm +++ b/runtime/queries/nasm/highlights.scm @@ -1,5 +1,4 @@ (comment) @comment -(ERROR) @error (label) @label From a7a526e425c0244ec881d3b551e5b80d4946b6df Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Thu, 23 Feb 2023 21:39:55 -0500 Subject: [PATCH 3/4] fix(queries/nasm): accept maintainer suggestions Co-authored-by: Michael Davis --- runtime/queries/nasm/highlights.scm | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/runtime/queries/nasm/highlights.scm b/runtime/queries/nasm/highlights.scm index 9c37177d8965..df9219fd7599 100644 --- a/runtime/queries/nasm/highlights.scm +++ b/runtime/queries/nasm/highlights.scm @@ -13,9 +13,9 @@ "}" @variable.builtin) (unary_expression - operator: _ @operator.unary) + operator: _ @operator) (binary_expression - operator: _ @operator.binary) + operator: _ @operator) (conditional_expression "?" @operator ":" @operator) @@ -54,10 +54,10 @@ (register) @constant.builtin -(number_literal) @number.integer +(number_literal) @constant.numeric.integer (string_literal) @string -(float_literal) @number.float -(packed_bcd_literal) @number.integer +(float_literal) @constant.numeric.float +(packed_bcd_literal) @constant.numeric.integer ((word) @constant (#match? @constant "^[A-Z_][?A-Z_0-9]+$")) From df213757f80e48498dfb5ea48de678c296af0f69 Mon Sep 17 00:00:00 2001 From: Matthew Toohey Date: Thu, 23 Feb 2023 22:37:18 -0500 Subject: [PATCH 4/4] fix(queries/nasm): highlight updates --- runtime/queries/nasm/highlights.scm | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/runtime/queries/nasm/highlights.scm b/runtime/queries/nasm/highlights.scm index df9219fd7599..5e3cfebe6f5b 100644 --- a/runtime/queries/nasm/highlights.scm +++ b/runtime/queries/nasm/highlights.scm @@ -2,15 +2,12 @@ (label) @label +(preproc_expression) @keyword.directive + [ - (preproc_expression) (line_here_token) (section_here_token) ] @variable.builtin -(preproc_expression - "]" @variable.builtin) -(preproc_expression - "}" @variable.builtin) (unary_expression operator: _ @operator) @@ -65,7 +62,7 @@ (#match? @constant.builtin "^__\\?[A-Z_a-z0-9]+\\?__$")) (word) @variable -(preproc_arg) @keyword +(preproc_arg) @keyword.directive [ (preproc_def) @@ -91,7 +88,7 @@ (preproc_pragma) (preproc_line) (preproc_clear) -] @keyword +] @keyword.directive [ (pseudo_instruction_dx) (pseudo_instruction_resx) @@ -99,7 +96,7 @@ (pseudo_instruction_equ_command) (pseudo_instruction_times_prefix) (pseudo_instruction_alignx_macro) -] @keyword +] @function.special [ (assembl_directive_target) (assembl_directive_defaults)