- Coming soon
- Try TQL online: https://tonyd33.github.io/tql/
tql --help
tql versionExample C source file:
#include <stddef.h>
#include <stdio.h>
int add(int a, int b) {
return a + b;
}
size_t strlen(const char *s) {
const char *p = s;
while (*p++) {}
return p - s;
}
int main(int argc, char **argv) {
printf("Hello world\n");
printf("strlen(\"Hello world\") = %lu\n", strlen("Hello world"));
printf("add(1, 2) = %d\n", add(1, 2));
return 0;
}Find all function names
tql query --grammar=c '
main = descendants_of_kind :function_definition | #declarator | #declarator | arr text;
' main.cOutput:
main.c: ["add","strlen","main"]
Find all function argument names
tql query --grammar=c '
main =
descendants_of_kind :function_definition
| #declarator
| #parameters
| descendants_of_kind :identifier
| arr text;
' main.cOutput:
main.c: ["a","b","s","argc","argv"]
Find all function argument names with type int
tql query --grammar=c '
int_type = #type | arr text | keep (\t -> t = "int");
main =
descendants_of_kind :function_definition
| #declarator
| #parameters
| children_of_kind :parameter_declaration
| keep (has int_type)
| #declarator
| arr text;
' main.cOutput:
main.c: ["a","b","argc"]
Find all function names with an argument with type int
tql query --grammar=c '
int_type = #type | arr text | keep (\t -> t = "int");
int_params = #declarator | #parameters | children_of_kind :parameter_declaration | keep (has int_type);
main =
descendants_of_kind :function_definition
| keep (has int_params)
| #declarator
| #declarator
| arr text;
' main.cOutput:
main.c: ["add","main"]
Find all function names with an argument with type int, along with that function's parameters
tql query --grammar=c '
params = #declarator | #parameters | children_of_kind :parameter_declaration;
int_type = #type | arr text | keep (\t -> t = "int");
main = do {
f <- descendants_of_kind :function_definition;
guard $ has (params | keep (has int_type)) f;
name <- pure f | #declarator | #declarator;
return { name = text name, params = run (params | arr text) f };
};
' main.cOutput:
main.c: [{"name":"add","params":["int a","int b"]},{"name":"main","params":["int argc","char **argv"]}]
List available grammars
tql grammar listExample output:
Built-in grammars:
(none)
Dynamic grammars:
c /home/user/.local/share/tql/grammars
python /home/user/.local/share/tql/grammars
rust /home/user/.local/share/tql/grammars
typescript /home/user/.local/share/tql/grammars
Download from releases
Requirements:
- Zig 0.16.0
cd packages/tql-engine-zig
# build with available grammars
zig build -Dgrammars=available
# build with only c grammar
zig build -Dgrammars=c