bindings.scm
1 ;; ═════════════════════════════════════════════════════════════════════════ 2 ;; Python Environment Variable Binding Queries 3 ;; ═════════════════════════════════════════════════════════════════════════ 4 5 ;; ─────────────────────────────────────────────────────────────────────────── 6 ;; x = os.environ["VAR"] 7 ;; x = os.environ.get("VAR") 8 ;; x = os.getenv("VAR") 9 ;; ─────────────────────────────────────────────────────────────────────────── 10 (assignment 11 left: (identifier) @binding_name 12 right: [ 13 ;; os.environ["VAR"] 14 (subscript 15 value: (attribute 16 object: (identifier) @_module 17 attribute: (identifier) @_object) 18 subscript: (string 19 (string_content) @bound_env_var) 20 (#eq? @_module "os") 21 (#eq? @_object "environ")) 22 ;; os.environ.get("VAR") 23 (call 24 function: (attribute 25 object: (attribute 26 object: (identifier) @_module 27 attribute: (identifier) @_object) 28 attribute: (identifier) @_method) 29 arguments: (argument_list 30 (string 31 (string_content) @bound_env_var) 32 (_)?) 33 (#eq? @_module "os") 34 (#eq? @_object "environ") 35 (#any-of? @_method "get" "pop" "setdefault")) 36 ;; os.getenv("VAR") 37 (call 38 function: (attribute 39 object: (identifier) @_module 40 attribute: (identifier) @_method) 41 arguments: (argument_list 42 (string 43 (string_content) @bound_env_var) 44 (_)?) 45 (#eq? @_module "os") 46 (#eq? @_method "getenv")) 47 48 ;; env = os.environ 49 (attribute 50 object: (identifier) @_module 51 attribute: (identifier) @_object 52 (#eq? @_module "os") 53 (#eq? @_object "environ")) 54 55 ;; env = os.environ.copy() 56 (call 57 function: (attribute 58 object: (attribute 59 object: (identifier) @_module 60 attribute: (identifier) @_object) 61 attribute: (identifier) @_method) 62 arguments: (argument_list) 63 (#eq? @_module "os") 64 (#eq? @_object "environ") 65 (#eq? @_method "copy")) 66 67 ]) @env_binding 68 69 ;; ─────────────────────────────────────────────────────────────────────────── 70 ;; env = os.environ (object alias) 71 ;; ─────────────────────────────────────────────────────────────────────────── 72 (assignment 73 left: (identifier) @binding_name 74 right: [ 75 ;; os.environ 76 (attribute 77 object: (identifier) @_module 78 attribute: (identifier) @_object 79 (#eq? @_module "os") 80 (#eq? @_object "environ")) 81 82 ;; os.environ.copy() 83 (call 84 function: (attribute 85 object: (attribute 86 object: (identifier) @_module 87 attribute: (identifier) @_object) 88 attribute: (identifier) @_method) 89 arguments: (argument_list) 90 (#eq? @_module "os") 91 (#eq? @_object "environ") 92 (#eq? @_method "copy")) 93 ] 94 ) @env_object_binding 95 96 ;; ═════════════════════════════════════════════════════════════════════════ 97 ;; Walrus Operator (:=) / Named Expression Patterns 98 ;; ═════════════════════════════════════════════════════════════════════════ 99 100 ;; ─────────────────────────────────────────────────────────────────────────── 101 ;; (x := os.environ["VAR"]) 102 ;; ─────────────────────────────────────────────────────────────────────────── 103 (named_expression 104 name: (identifier) @binding_name 105 value: (subscript 106 value: (attribute 107 object: (identifier) @_module 108 attribute: (identifier) @_object) 109 subscript: (string 110 (string_content) @bound_env_var)) 111 (#eq? @_module "os") 112 (#eq? @_object "environ")) @env_binding 113 114 ;; ─────────────────────────────────────────────────────────────────────────── 115 ;; (x := os.environ.get("VAR")) 116 ;; ─────────────────────────────────────────────────────────────────────────── 117 (named_expression 118 name: (identifier) @binding_name 119 value: (call 120 function: (attribute 121 object: (attribute 122 object: (identifier) @_module 123 attribute: (identifier) @_object) 124 attribute: (identifier) @_method) 125 arguments: (argument_list 126 (string 127 (string_content) @bound_env_var) 128 (_)?)) 129 (#eq? @_module "os") 130 (#eq? @_object "environ") 131 (#any-of? @_method "get" "pop" "setdefault")) @env_binding 132 133 ;; ─────────────────────────────────────────────────────────────────────────── 134 ;; (x := os.getenv("VAR")) 135 ;; ─────────────────────────────────────────────────────────────────────────── 136 (named_expression 137 name: (identifier) @binding_name 138 value: (call 139 function: (attribute 140 object: (identifier) @_module 141 attribute: (identifier) @_method) 142 arguments: (argument_list 143 (string 144 (string_content) @bound_env_var) 145 (_)?)) 146 (#eq? @_module "os") 147 (#eq? @_method "getenv")) @env_binding 148 149 ;; ═════════════════════════════════════════════════════════════════════════ 150 ;; Config Class Attribute Patterns 151 ;; ═════════════════════════════════════════════════════════════════════════ 152 153 ;; ─────────────────────────────────────────────────────────────────────────── 154 ;; class Config: 155 ;; DB = os.environ['DB'] 156 ;; ─────────────────────────────────────────────────────────────────────────── 157 (class_definition 158 body: (block 159 (expression_statement 160 (assignment 161 left: (identifier) @binding_name 162 right: (subscript 163 value: (attribute 164 object: (identifier) @_module 165 attribute: (identifier) @_attr) 166 subscript: (string 167 (string_content) @bound_env_var)) 168 (#eq? @_module "os") 169 (#eq? @_attr "environ"))))) @env_binding 170 171 ;; ─────────────────────────────────────────────────────────────────────────── 172 ;; class Config: 173 ;; DB = os.getenv('DB') 174 ;; ─────────────────────────────────────────────────────────────────────────── 175 (class_definition 176 body: (block 177 (expression_statement 178 (assignment 179 left: (identifier) @binding_name 180 right: (call 181 function: (attribute 182 object: (identifier) @_module 183 attribute: (identifier) @_method) 184 arguments: (argument_list 185 (string 186 (string_content) @bound_env_var) 187 (_)?)) 188 (#eq? @_module "os") 189 (#eq? @_method "getenv"))))) @env_binding 190 191 ;; ─────────────────────────────────────────────────────────────────────────── 192 ;; class Config: 193 ;; DB = os.environ.get('DB') 194 ;; ─────────────────────────────────────────────────────────────────────────── 195 (class_definition 196 body: (block 197 (expression_statement 198 (assignment 199 left: (identifier) @binding_name 200 right: (call 201 function: (attribute 202 object: (attribute 203 object: (identifier) @_module 204 attribute: (identifier) @_object) 205 attribute: (identifier) @_method) 206 arguments: (argument_list 207 (string 208 (string_content) @bound_env_var) 209 (_)?)) 210 (#eq? @_module "os") 211 (#eq? @_object "environ") 212 (#any-of? @_method "get" "pop" "setdefault"))))) @env_binding 213 214 ;; ═════════════════════════════════════════════════════════════════════════ 215 ;; python-dotenv / decouple bindings 216 ;; ═════════════════════════════════════════════════════════════════════════ 217 218 ;; ─────────────────────────────────────────────────────────────────────────── 219 ;; x = dotenv.get_key('.env', 'VAR') 220 ;; ─────────────────────────────────────────────────────────────────────────── 221 (assignment 222 left: (identifier) @binding_name 223 right: (call 224 function: (attribute 225 object: (identifier) @_module 226 attribute: (identifier) @_method) 227 arguments: (argument_list 228 (_) 229 (string 230 (string_content) @bound_env_var))) 231 (#eq? @_module "dotenv") 232 (#eq? @_method "get_key")) @env_binding 233 234 ;; ─────────────────────────────────────────────────────────────────────────── 235 ;; x = config('VAR') (decouple) 236 ;; ─────────────────────────────────────────────────────────────────────────── 237 (assignment 238 left: (identifier) @binding_name 239 right: (call 240 function: (identifier) @_func 241 arguments: (argument_list 242 (string 243 (string_content) @bound_env_var) 244 (_)?)) 245 (#eq? @_func "config")) @env_binding 246 247 ;; ─────────────────────────────────────────────────────────────────────────── 248 ;; x = decouple.config('VAR') 249 ;; ─────────────────────────────────────────────────────────────────────────── 250 (assignment 251 left: (identifier) @binding_name 252 right: (call 253 function: (attribute 254 object: (identifier) @_module 255 attribute: (identifier) @_func) 256 arguments: (argument_list 257 (string 258 (string_content) @bound_env_var) 259 (_)?)) 260 (#eq? @_module "decouple") 261 (#eq? @_func "config")) @env_binding