aboutsummaryrefslogtreecommitdiff
path: root/tools/tree-sitter/queries
diff options
context:
space:
mode:
authorEugen Wissner <belka@caraus.de>2026-10-05 00:26:05 +0200
committerEugen Wissner <belka@caraus.de>2026-10-05 01:00:50 +0200
commita9f6cfb6a8b6d38057faca067c015da1f72cf62d (patch)
treedb4e740db52df8be62bda5d2101603910107b7d4 /tools/tree-sitter/queries
parent5b7f983b3912a8d0fbeaf22f7fe0e2c5f1e0ff01 (diff)
downloadelna-a9f6cfb6a8b6d38057faca067c015da1f72cf62d.tar.gz
Add a treesitter grammar
Diffstat (limited to 'tools/tree-sitter/queries')
-rw-r--r--tools/tree-sitter/queries/elna/folds.scm20
-rw-r--r--tools/tree-sitter/queries/elna/highlights.scm201
-rw-r--r--tools/tree-sitter/queries/elna/indents.scm22
-rw-r--r--tools/tree-sitter/queries/elna/locals.scm33
4 files changed, 276 insertions, 0 deletions
diff --git a/tools/tree-sitter/queries/elna/folds.scm b/tools/tree-sitter/queries/elna/folds.scm
new file mode 100644
index 0000000..0387513
--- /dev/null
+++ b/tools/tree-sitter/queries/elna/folds.scm
@@ -0,0 +1,20 @@
+[
+ (module_declaration)
+ (program_declaration)
+ (procedure_declaration)
+ (record_type)
+ (enum_type)
+ (block)
+ (if_statement)
+ (elsif_clause)
+ (else_clause)
+ (while_statement)
+ (while_elsif_clause)
+ (repeat_statement)
+ (for_statement)
+ (defer_statement)
+ (block_statement)
+ (case_statement)
+ (case_arm)
+ (comment)
+] @fold
diff --git a/tools/tree-sitter/queries/elna/highlights.scm b/tools/tree-sitter/queries/elna/highlights.scm
new file mode 100644
index 0000000..b5e6d10
--- /dev/null
+++ b/tools/tree-sitter/queries/elna/highlights.scm
@@ -0,0 +1,201 @@
+; Keywords
+[
+ "program"
+ "module"
+ "type"
+ "var"
+ "threadvar"
+ "record"
+ "extern"
+ "defer"
+ "block"
+ "break"
+ "with"
+ "to"
+ "cast"
+ "begin"
+ "end"
+] @keyword
+
+"proc" @keyword.function
+"return" @keyword.return
+"import" @keyword.import
+
+[
+ "while"
+ "do"
+ "for"
+ "repeat"
+ "until"
+] @keyword.repeat
+
+[
+ "if"
+ "then"
+ "else"
+ "elsif"
+ "case"
+ "of"
+] @keyword.conditional
+
+"const" @keyword.modifier
+
+[
+ "or"
+ "xor"
+] @keyword.operator
+
+; Comments
+(comment) @comment @spell
+
+; Literals
+(integer) @number
+(float) @number.float
+(boolean) @boolean
+(nil) @constant.builtin
+
+(string) @string
+(character) @character
+(byte) @character
+(escape_sequence) @string.escape
+
+; Traits and Attributes
+(trait) @attribute
+(attribute
+ "#{" @punctuation.special
+ name: (identifier) @attribute
+ "}" @punctuation.special)
+
+; Builtin Types
+((identifier) @type.builtin
+ (#any-of? @type.builtin
+ "Int" "Word"
+ "Int8" "Int16" "Int32" "Int64"
+ "Word8" "Word16" "Word32" "Word64"
+ "Single" "Double"
+ "Char" "Pointer" "Bool"))
+
+; Declarations and Definitions
+(type_declaration
+ name: (identifier_definition
+ name: (identifier) @type.definition))
+
+(type_parameters
+ (identifier) @type.parameter)
+
+(type_arguments
+ (identifier) @type)
+
+(record_type
+ base: (identifier) @type)
+
+(record_constructor
+ type: (identifier) @type)
+
+(generic_type
+ name: (identifier) @type)
+
+(cast_expression
+ type: (identifier) @type)
+
+(traits_expression
+ arguments: (identifier) @type)
+
+(enum_type
+ member: (identifier) @constant)
+
+(procedure_declaration
+ name: (identifier_definition
+ name: (identifier) @function))
+
+(identifier_definition
+ exported: "*" @punctuation.special)
+
+(field_declaration
+ names: (identifier_definition
+ name: (identifier) @variable.member))
+
+(parameter_list
+ (field_declaration
+ names: (identifier_definition
+ name: (identifier) @variable.parameter)))
+
+(variable_declaration
+ names: (identifier_definition
+ name: (identifier) @variable))
+
+(for_statement
+ variable: (identifier) @variable
+ counter: (identifier)? @variable)
+
+(block_statement
+ name: (identifier) @label)
+
+(break_statement
+ label: (identifier) @label)
+
+(import_path
+ (identifier) @module)
+
+; Calls and Member Access
+(call_expression
+ function: (identifier) @function.call)
+
+(call_expression
+ function: (field_expression
+ field: (identifier) @function.method.call))
+
+(field_expression
+ field: (identifier) @variable.member)
+
+(field_initializer
+ name: (identifier) @variable.member)
+
+; Fallback identifiers
+(identifier) @variable
+
+; Operators
+[
+ ":="
+ "="
+ "<>"
+ "<"
+ ">"
+ "<="
+ ">="
+ "+"
+ "-"
+ "*"
+ "/"
+ "%"
+ "<<"
+ ">>"
+ "&"
+ "|"
+ "~"
+ "->"
+ "^"
+ "@"
+] @operator
+
+; Delimiters and Punctuation
+[
+ ";"
+ ","
+ ":"
+ "."
+] @punctuation.delimiter
+
+[
+ "("
+ ")"
+ "["
+ "]"
+ "{"
+ "}"
+] @punctuation.bracket
+
+[
+ "#["
+ "#{"
+] @punctuation.special
diff --git a/tools/tree-sitter/queries/elna/indents.scm b/tools/tree-sitter/queries/elna/indents.scm
new file mode 100644
index 0000000..0e807d0
--- /dev/null
+++ b/tools/tree-sitter/queries/elna/indents.scm
@@ -0,0 +1,22 @@
+[
+ (type_section)
+ (var_section)
+ (threadvar_section)
+ (procedure_body)
+ (block)
+ (record_type)
+ (case_arm)
+] @indent.begin
+
+[
+ "end"
+ "until"
+ (return_clause)
+] @indent.end
+
+[
+ "begin"
+ (elsif_clause)
+ (else_clause)
+ (while_elsif_clause)
+] @indent.branch
diff --git a/tools/tree-sitter/queries/elna/locals.scm b/tools/tree-sitter/queries/elna/locals.scm
new file mode 100644
index 0000000..1e9bb70
--- /dev/null
+++ b/tools/tree-sitter/queries/elna/locals.scm
@@ -0,0 +1,33 @@
+[
+ (source_file)
+ (module_declaration)
+ (program_declaration)
+ (procedure_declaration)
+ (procedure_body)
+ (block)
+ (block_statement)
+ (if_statement)
+ (while_statement)
+ (for_statement)
+ (repeat_statement)
+ (case_statement)
+] @local.scope
+
+(variable_declaration
+ names: (identifier_definition
+ name: (identifier) @local.definition))
+
+(parameter_list
+ (field_declaration
+ names: (identifier_definition
+ name: (identifier) @local.definition)))
+
+(for_statement
+ variable: (identifier) @local.definition
+ counter: (identifier)? @local.definition)
+
+(procedure_declaration
+ name: (identifier_definition
+ name: (identifier) @local.definition))
+
+(identifier) @local.reference