Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add nasm language #6068

Merged
merged 4 commits into from
Feb 25, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions book/src/generated/lang-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
| meson | ✓ | | ✓ | |
| mint | | | | `mint` |
| msbuild | ✓ | | ✓ | |
| nasm | ✓ | ✓ | | |
| nickel | ✓ | | ✓ | `nls` |
| nix | ✓ | | | `nil` |
| nu | ✓ | | | |
Expand Down
13 changes: 13 additions & 0 deletions languages.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
129 changes: 129 additions & 0 deletions runtime/queries/nasm/highlights.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
(comment) @comment

(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)
mtoohey31 marked this conversation as resolved.
Show resolved Hide resolved
(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
mtoohey31 marked this conversation as resolved.
Show resolved Hide resolved

((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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the preprocessor stuff is like the C preprocessor, these might fall under @keyword.directive https://docs.helix-editor.com/master/themes.html#syntax-highlighting

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you're right that @keyword.directive makes more sense. I've switched it to that in df21375 along with a few other improvements.


[
(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
2 changes: 2 additions & 0 deletions runtime/queries/nasm/injections.scm
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
((comment) @injection.content
(#set! injection.language "comment"))
15 changes: 15 additions & 0 deletions runtime/queries/nasm/textobjects.scm
Original file line number Diff line number Diff line change
@@ -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