grammar-inference-engine/bex/queries/universal.scm

133 lines
2.9 KiB
Scheme
Raw Normal View History

; UNIVERSAL DERVISH QUERY
;
; One query to extract behavioral tokens from any TreeSitter-supported language.
; TreeSitter silently ignores non-existent node types at query time,
; so we can reference nodes from all languages safely.
;
; Captures:
; @qualified-call — obj.method() → "obj.method"
; @simple-call — bare method() → "method"
; @annotation — @Annotation → "@Annotation"
; @constructor — new Type() / Type() → "Type"
;; === JAVA ===
; obj.method()
(method_invocation
object: (identifier) @object
name: (identifier) @method) @qualified-call
; method() (no explicit object)
(method_invocation
name: (identifier) @method
!object) @simple-call
; @Annotation
(annotation
name: (identifier) @name) @annotation
; @Annotation (no args)
(marker_annotation
name: (identifier) @name) @annotation
; new Type()
(object_creation_expression
type: (type_identifier) @name) @constructor
;; === KOTLIN ===
; obj.method()
(navigation_expression
(identifier) @object
(identifier) @method) @qualified-call
; method() bare call (Kotlin top-level function)
(call_expression
function: (identifier) @method) @simple-call
; @Annotation (simple)
(annotation
(user_type) @name) @annotation
; @Annotation(args)
(annotation
(constructor_invocation
(user_type) @name)) @annotation
;; === PYTHON ===
; obj.method()
(call
function: (attribute
object: (identifier) @object
attribute: (identifier) @method)) @qualified-call
; method() bare call
(call
function: (identifier) @method) @simple-call
; @decorator
(decorator
(identifier) @name) @annotation
; @decorator(args)
(decorator
(attribute
attribute: (identifier) @name)) @annotation
;; === GO ===
; obj.method()
(call_expression
function: (selector_expression
operand: (identifier) @object
field: (field_identifier) @method)) @qualified-call
; method() bare call
(call_expression
function: (identifier) @method) @simple-call
;; === RUST ===
; obj::method()
(call_expression
function: (scoped_identifier
path: (identifier) @object
name: (identifier) @method)) @qualified-call
; obj.method()
(call_expression
function: (field_expression
value: (identifier) @object
field: (field_identifier) @method)) @qualified-call
; method() bare call
(call_expression
function: (identifier) @method) @simple-call
;; === TYPE-SCRIPT / JAVASCRIPT ===
; obj.method()
(call_expression
function: (member_expression
object: (identifier) @object
property: (property_identifier) @method)) @qualified-call
; method() bare call
(call_expression
function: (identifier) @method) @simple-call
; new Type()
(new_expression
constructor: (identifier) @name) @constructor
;; === C / C++ ===
(call_expression
function: (field_expression
argument: (identifier) @object
field: (field_identifier) @method)) @qualified-call
(call_expression
function: (identifier) @method) @simple-call