From 05c0183daccde6a5ef8d5a80d4ede3e3be656340 Mon Sep 17 00:00:00 2001 From: StackApe Date: Sun, 14 Dec 2025 09:27:59 -0500 Subject: [PATCH] feat: add ApX parser ApX is a command-oriented scripting language for the APEX PDE (Personal Development Environment). It features pipelines, 200+ built-in commands, control flow, functions, macros, and more. Grammar repository: https://github.com/StackApe/tree-sitter-apx --- lua/nvim-treesitter/parsers.lua | 8 ++ queries/apx/highlights.scm | 161 ++++++++++++++++++++++++++++++++ queries/apx/locals.scm | 39 ++++++++ 3 files changed, 208 insertions(+) create mode 100644 queries/apx/highlights.scm create mode 100644 queries/apx/locals.scm diff --git a/lua/nvim-treesitter/parsers.lua b/lua/nvim-treesitter/parsers.lua index 9aaf4c477..3a4964c46 100644 --- a/lua/nvim-treesitter/parsers.lua +++ b/lua/nvim-treesitter/parsers.lua @@ -34,6 +34,14 @@ return { maintainers = { '@aheber', '@xixiafinland' }, tier = 2, }, + apx = { + install_info = { + revision = 'b4998766b748d9559a5d1752b76b2719721bd096', + url = 'https://github.com/StackApe/tree-sitter-apx', + }, + maintainers = { '@StackApe' }, + tier = 2, + }, arduino = { install_info = { revision = '53eb391da4c6c5857f8defa2c583c46c2594f565', diff --git a/queries/apx/highlights.scm b/queries/apx/highlights.scm new file mode 100644 index 000000000..f1d142856 --- /dev/null +++ b/queries/apx/highlights.scm @@ -0,0 +1,161 @@ +; ApX Tree-sitter highlight queries for Neovim + +; Comments +(comment) @comment + +; Strings +(double_string) @string +(single_string) @string +(triple_string) @string +(raw_string) @string +(backtick_string) @string + +; Numbers +(integer) @number +(float) @number.float +(hex_number) @number +(binary_number) @number +(octal_number) @number + +; Booleans and null +(boolean) @boolean +(null) @constant.builtin + +; Variables +(regular_variable) @variable +(env_variable) @variable.builtin +(special_variable) @variable.builtin + +; Field access: $var.field +(field_access + (identifier) @property) + +; Method calls: ai.ask +(method_call + (identifier) @function.call) + +; Keywords - Control flow (using actual grammar keywords) +"if" @keyword.control +"else" @keyword.control +"elif" @keyword.control +"for" @keyword.control +"while" @keyword.control +"in" @keyword.control +"match" @keyword.control +"return" @keyword.control + +; Break and continue are statement nodes +(break_statement) @keyword.control +(continue_statement) @keyword.control + +; Keywords - Definition +"fn" @keyword.function +"macro" @keyword.function +"alias" @keyword.function +"let" @keyword.function +"const" @keyword.function +"set" @keyword.function + +; Keywords - Error handling +"try" @keyword.exception +"catch" @keyword.exception + +; Keywords - Modules +"use" @keyword.import +"from" @keyword.import +"import" @keyword.import +"as" @keyword.import + +; Keywords - Testing +"test" @keyword + +; Keywords - Logical +"and" @keyword.operator +"or" @keyword.operator +"not" @keyword.operator + +; Operators +[ + "+" + "-" + "*" + "/" + "%" + "==" + "!=" + "<" + ">" + "<=" + ">=" + "&&" + "||" + "!" + "=" + "|" + ".." + "..=" + "=>" +] @operator + +; Punctuation +[ + "(" + ")" + "[" + "]" + "{" + "}" +] @punctuation.bracket + +[ + "," + ":" + "::" +] @punctuation.delimiter + +; Function definition - identifier after 'fn' +(function_definition + (identifier) @function.definition) + +; Macro definition - identifier after 'macro' +(macro_definition + (identifier) @function.macro) + +; Alias definition - identifier after 'alias' +(alias_definition + (identifier) @function) + +; Test definition +(test_definition + (string) @string.special) + +; Function parameters +(parameter + (identifier) @variable.parameter) + +; Record fields +(record_field + (identifier) @property) + +; Import +(import_item + (identifier) @namespace) + +; Flags +(long_flag) @attribute +(short_flag) @attribute + +; Built-in commands +(builtin_command) @function.builtin + +; User-defined command calls +(command_expression + (command_name + (identifier) @function.call)) + +; Match arms +(match_arm + (_) @constant) + +; Range +(range) @constant diff --git a/queries/apx/locals.scm b/queries/apx/locals.scm new file mode 100644 index 000000000..7a27543bb --- /dev/null +++ b/queries/apx/locals.scm @@ -0,0 +1,39 @@ +; ApX Tree-sitter locals queries for scope tracking + +; Scopes +(function_definition) @local.scope +(macro_definition) @local.scope +(closure) @local.scope +(for_statement) @local.scope +(block) @local.scope + +; Definitions +(assignment + (identifier) @local.definition) + +(variable_assignment + (variable) @local.definition) + +(parameter + (identifier) @local.definition) + +(function_definition + (identifier) @local.definition) + +(macro_definition + (identifier) @local.definition) + +(alias_definition + (identifier) @local.definition) + +(for_statement + (identifier) @local.definition) + +(closure_parameters + (identifier) @local.definition) + +; References +(regular_variable) @local.reference +(command_expression + (command_name + (identifier) @local.reference))