//
//  RustQueries.swift
//  RepoPrompt
//
//  Created by Eric Provencher on 2025-02-06.
//

// RustQuery.swift
// Make sure no tab characters are present; use only spaces for indentation.

import Foundation

let rustQuery = """
; Identifiers

 (type_identifier) @type
 (primitive_type) @type.builtin
 (field_identifier) @property

; Identifier conventions

; Assume all-caps names are constants
 ((identifier) @constant
  (#match? @constant "^[A-Z][A-Z\\d_]+$'"))

; Assume uppercase names are enum constructors
((identifier) @constructor
 (#match? @constructor "^[A-Z]"))

; Assume that uppercase names in paths are types
 ((scoped_identifier
   path: (identifier) @type)
  (#match? @type "^[A-Z]"))
((scoped_identifier
  path: (scoped_identifier
   name: (identifier) @type))
 (#match? @type "^[A-Z]"))
((scoped_type_identifier
  path: (identifier) @type)
 (#match? @type "^[A-Z]"))
((scoped_type_identifier
  path: (scoped_identifier
   name: (identifier) @type))
 (#match? @type "^[A-Z]"))

; Assume all qualified names in struct patterns are enum constructors. (They're
				  ; either that, or struct names; highlighting both as constructors seems to be
				  ; the less glaring choice of error, visually.)
(struct_pattern
 type: (scoped_type_identifier
  name: (type_identifier) @constructor))

; Function calls

 (call_expression
  function: (identifier) @function)
(call_expression
 function: (field_expression
   field: (field_identifier) @function.method))
(call_expression
 function: (scoped_identifier
   "::"
   name: (identifier) @function))

(generic_function
 function: (identifier) @function)
(generic_function
 function: (scoped_identifier
   name: (identifier) @function))
(generic_function
 function: (field_expression
   field: (field_identifier) @function.method))

(macro_invocation
 macro: (identifier) @function.macro
 "!" @function.macro)

; Function definitions

 (function_item (identifier) @function)
(function_signature_item (identifier) @function)

(line_comment) @comment
 (block_comment) @comment

 (line_comment (doc_comment)) @comment.documentation
 (block_comment (doc_comment)) @comment.documentation

"(" @punctuation.bracket
")" @punctuation.bracket
"[" @punctuation.bracket
"]" @punctuation.bracket
"{" @punctuation.bracket
"}" @punctuation.bracket

 (type_arguments
  "<" @punctuation.bracket
  ">" @punctuation.bracket)
(type_parameters
 "<" @punctuation.bracket
 ">" @punctuation.bracket)

"::" @punctuation.delimiter
":" @punctuation.delimiter
"." @punctuation.delimiter
"," @punctuation.delimiter
";" @punctuation.delimiter

 (parameter (identifier) @variable.parameter)

(lifetime (identifier) @label)

"as" @keyword
"async" @keyword
"await" @keyword
"break" @keyword
"const" @keyword
"continue" @keyword
"default" @keyword
"dyn" @keyword
"else" @keyword
"enum" @keyword
"extern" @keyword
"fn" @keyword
"for" @keyword
"gen" @keyword
"if" @keyword
"impl" @keyword
"in" @keyword
"let" @keyword
"loop" @keyword
"macro_rules!" @keyword
"match" @keyword
"mod" @keyword
"move" @keyword
"pub" @keyword
"raw" @keyword
"ref" @keyword
"return" @keyword
"static" @keyword
"struct" @keyword
"trait" @keyword
"type" @keyword
"union" @keyword
"unsafe" @keyword
"use" @keyword
"where" @keyword
"while" @keyword
"yield" @keyword
 (crate) @keyword
 (mutable_specifier) @keyword
 (use_list (self) @keyword)
(scoped_use_list (self) @keyword)
(scoped_identifier (self) @keyword)
(super) @keyword

 (self) @variable.builtin

 (char_literal) @string
 (string_literal) @string
 (raw_string_literal) @string

 (boolean_literal) @constant.builtin
 (integer_literal) @constant.builtin
 (float_literal) @constant.builtin

 (escape_sequence) @escape

 (attribute_item) @attribute
 (inner_attribute_item) @attribute

"*" @operator
"&" @operator
"'" @operator
"""

let rustCodeMapQuery = #"""
; ===================================
; 1) Struct Declarations
; ===================================
(struct_item
  (type_identifier) @type.struct) @type.class.decl

; ===================================
; 2) Import Declarations
; ===================================
(use_declaration) @import

; ===================================
; 3) Function Declarations
;    (top-level free functions only)
; ----------------------------------
(source_file
	(function_item
	(identifier) @function.definition))

(source_file
	(function_signature_item
	(identifier) @function.definition))

; ===================================
; 4) Global Variables
;    Typically top-level `const_item` or `static_item`.
; ===================================
(const_item
  (identifier) @variable.global)

(static_item
  (identifier) @variable.global)

; ===================================
; 5) Struct Fields
;    If you want only `pub` fields, you’ll need extra logic.
; ===================================
(field_declaration
  (field_identifier) @variable.field)

; ===================================
; 6) Enum Declarations
; ===================================
(enum_item
  (type_identifier) @type.enum) @type.enum.decl

; ===================================
; 7) Enum Variants
; ===================================
(enum_variant
  (identifier) @enum.entry)

; ===================================
; 8) Trait Declarations
; ===================================
(trait_item
  (type_identifier) @type.interface) @type.interface.decl

; ===================================
; 9) Impl Items (methods inside impl)
;    Functions appear under a `declaration_list`.
; ===================================
(impl_item
  type: (type_identifier) @rust.impl.type
) @rust.impl.decl

(impl_item
  type: (generic_type
    type: (type_identifier) @rust.impl.type
  )
) @rust.impl.decl

(impl_item
  (declaration_list
	(function_item
	  (identifier) @function.definition
	)+
  )
)
"""#
