feat: added many diffrent grammars (llm assisted)

This commit is contained in:
Grace Yoder 2026-07-15 17:17:12 -06:00
parent 6a3f7b3fde
commit 5efd9cd3be
Signed by: grace
SSH key fingerprint: SHA256:oG9v0ZlohsoMAg083HAwBGOcaPLF3nIuOlAW4MtASMo
4 changed files with 2998 additions and 0 deletions

1314
build.zig

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

279
src/tests.zig Normal file
View file

@ -0,0 +1,279 @@
const std = @import("std");
const testing = std.testing;
const ts = @import("tree-sitter");
const ezts = @import("eazy_zig_tree_sitter");
const grammars = @import("grammars");
const queries_mod = @import("queries");
const Entry = struct { key: []const u8, source: []const u8 };
fn runParseTest(entries: []const Entry) !void {
for (entries) |e| {
const lang = ezts.getLang(e.key) orelse @panic("unknown lang");
defer lang.destroy();
var parser = ts.Parser.create();
defer parser.destroy();
try parser.setLanguage(lang);
const tree = parser.parseString(e.source, null) orelse {
std.debug.print("PARSE FAIL: {s}\n", .{e.key});
return error.ParseFailed;
};
defer tree.destroy();
}
}
fn runQueryTest(entries: []const Entry) !void {
for (entries) |e| {
const lang = ezts.getLang(e.key) orelse @panic("unknown lang");
defer lang.destroy();
var parser = ts.Parser.create();
defer parser.destroy();
try parser.setLanguage(lang);
const tree = parser.parseString(e.source, null) orelse continue;
defer tree.destroy();
const query_src = ezts.getQuery(e.key) orelse {
std.debug.print("NO QUERY: {s}\n", .{e.key});
continue;
};
var error_offset: u32 = 0;
const query = ts.Query.create(lang, query_src, &error_offset) catch |err| {
std.debug.print("QUERY ERROR {s}: {s} at {d}\n", .{ e.key, @errorName(err), error_offset });
return error.QueryFailed;
};
defer query.destroy();
const cursor = ts.QueryCursor.create();
defer cursor.destroy();
cursor.exec(query, tree.rootNode());
_ = cursor.nextCapture();
}
}
const parse_entries: []const Entry = &.{
.{ .key = "c", .source = "int a;" },
.{ .key = "md", .source = "# hi" },
.{ .key = "md_inline", .source = "**hi**" },
.{ .key = "lua", .source = "x=1" },
.{ .key = "cuda", .source = "int a;" },
.{ .key = "glsl", .source = "int a;" },
.{ .key = "diff", .source = "+a" },
.{ .key = "ungrammar", .source = "A = 'a'" },
.{ .key = "thrift", .source = "struct A{}" },
.{ .key = "meson", .source = "x=1" },
.{ .key = "gitattributes", .source = "* text" },
.{ .key = "pymanifest", .source = "" },
.{ .key = "poe_filter", .source = "" },
.{ .key = "chatito", .source = "" },
.{ .key = "ino", .source = "void setup(){}" },
.{ .key = "capnp", .source = "struct A{}" },
.{ .key = "kdl", .source = "node1" },
.{ .key = "func", .source = "" },
.{ .key = "gosum", .source = "" },
.{ .key = "ron", .source = "()" },
.{ .key = "po", .source = "" },
.{ .key = "starlark", .source = "x=1" },
.{ .key = "yuck", .source = "" },
.{ .key = "smali", .source = ".class public A" },
.{ .key = "bicep", .source = "" },
.{ .key = "cpon", .source = "" },
.{ .key = "firrtl", .source = "" },
.{ .key = "luap", .source = "" },
.{ .key = "squirrel", .source = "x=1" },
.{ .key = "uxntal", .source = "" },
.{ .key = "cairo", .source = "func main(){}" },
.{ .key = "odin", .source = "main :: proc(){}" },
.{ .key = "hare", .source = "export fn main() void;" },
.{ .key = "pony", .source = "actor Main" },
.{ .key = "tablegen", .source = "" },
.{ .key = "luadoc", .source = "" },
.{ .key = "puppet", .source = "$a=1" },
.{ .key = "luau", .source = "x=1" },
.{ .key = "objc", .source = "int a;" },
.{ .key = "ispc", .source = "int a;" },
.{ .key = "pem", .source = "" },
.{ .key = "requirements", .source = "a" },
.{ .key = "gpg", .source = "" },
.{ .key = "bb", .source = "A = \"1\"" },
.{ .key = "csv", .source = "a,b" },
.{ .key = "psv", .source = "a|b" },
.{ .key = "tsv", .source = "a\tb" },
.{ .key = "printf", .source = "" },
.{ .key = "re2c", .source = "" },
.{ .key = "doxygen", .source = "" },
.{ .key = "ssh_config", .source = "Host *" },
.{ .key = "nqc", .source = "" },
.{ .key = "kconfig", .source = "mainmenu \"x\"" },
.{ .key = "gn", .source = "executable(\"a\") {}" },
.{ .key = "udev", .source = "" },
.{ .key = "xcompose", .source = "" },
.{ .key = "linkerscript", .source = "" },
.{ .key = "properties", .source = "key=value" },
.{ .key = "readline", .source = "" },
.{ .key = "Makefile", .source = "x=a" },
.{ .key = "yaml", .source = "a: 1" },
.{ .key = "toml", .source = "a=1" },
.{ .key = "svelte", .source = "" },
.{ .key = "scss", .source = "$a:1" },
.{ .key = "cst", .source = "" },
.{ .key = "jl", .source = "x=1" },
.{ .key = "hs", .source = "x=1" },
.{ .key = "cyberchef", .source = "" },
.{ .key = "js", .source = "1" },
.{ .key = "json", .source = "1" },
.{ .key = "cpp", .source = "int a;" },
.{ .key = "rb", .source = "x=1" },
.{ .key = "go", .source = "package p" },
.{ .key = "cs", .source = "class A{}" },
.{ .key = "py", .source = "x=1" },
.{ .key = "rs", .source = "fn f(){}" },
.{ .key = "sh", .source = "true" },
.{ .key = "java", .source = "class A{}" },
.{ .key = "scala", .source = "class A" },
.{ .key = "agda", .source = "" },
.{ .key = "html", .source = "<p>" },
.{ .key = "embedded_template", .source = "" },
.{ .key = "regex", .source = "a" },
.{ .key = "css", .source = "a{}" },
.{ .key = "jsdoc", .source = "/** */" },
.{ .key = "ql", .source = "" },
.{ .key = "query", .source = "" },
.{ .key = "lisp", .source = "()" },
.{ .key = "tf", .source = "" },
.{ .key = "hcl", .source = "" },
.{ .key = "hlsl", .source = "int a;" },
.{ .key = "tcl", .source = "" },
.{ .key = "chatl", .source = "" },
.{ .key = "wgsl_bevy", .source = "" },
.{ .key = "move", .source = "" },
.{ .key = "kt", .source = "fun f(){}" },
.{ .key = "vim", .source = "" },
.{ .key = "hyprlang", .source = "" },
.{ .key = "gstlaunch", .source = "" },
.{ .key = "slang", .source = "" },
.{ .key = "dtd", .source = "" },
.{ .key = "xml", .source = "<a/>" },
.{ .key = "core_schema", .source = "" },
.{ .key = "json_schema", .source = "" },
.{ .key = "legacy_schema", .source = "" },
.{ .key = "vue", .source = "" },
.{ .key = "qmldir", .source = "" },
.{ .key = "zig", .source = "const a=1;" },
.{ .key = "test", .source = "" },
.{ .key = "v", .source = "" },
.{ .key = "tsx", .source = "<a/>" },
.{ .key = "ts", .source = "let a=1" },
.{ .key = "php", .source = "<?php" },
.{ .key = "php_only", .source = "<?php" },
.{ .key = "mli", .source = "" },
.{ .key = "ml", .source = "let a=1" },
.{ .key = "mly", .source = "" },
.{ .key = "fluent", .source = "" },
.{ .key = "tsq", .source = "" },
.{ .key = "ql_dbscheme", .source = "" },
};
const query_entries: []const Entry = &.{
.{ .key = "c", .source = "int a;" },
.{ .key = "md", .source = "# hi" },
.{ .key = "md_inline", .source = "**hi**" },
.{ .key = "lua", .source = "x=1" },
.{ .key = "cuda", .source = "int a;" },
.{ .key = "glsl", .source = "int a;" },
.{ .key = "diff", .source = "+a" },
.{ .key = "ungrammar", .source = "A = 'a'" },
.{ .key = "thrift", .source = "struct A{}" },
.{ .key = "meson", .source = "x=1" },
.{ .key = "gitattributes", .source = "* text" },
.{ .key = "pymanifest", .source = "" },
.{ .key = "poe_filter", .source = "" },
.{ .key = "chatito", .source = "" },
.{ .key = "ino", .source = "void setup(){}" },
.{ .key = "capnp", .source = "struct A{}" },
.{ .key = "kdl", .source = "node1" },
.{ .key = "func", .source = "" },
.{ .key = "gosum", .source = "" },
.{ .key = "ron", .source = "()" },
.{ .key = "po", .source = "" },
.{ .key = "starlark", .source = "x=1" },
.{ .key = "yuck", .source = "" },
.{ .key = "smali", .source = ".class public A" },
.{ .key = "bicep", .source = "" },
.{ .key = "cpon", .source = "" },
.{ .key = "firrtl", .source = "" },
.{ .key = "luap", .source = "" },
.{ .key = "squirrel", .source = "x=1" },
.{ .key = "uxntal", .source = "" },
.{ .key = "cairo", .source = "func main(){}" },
.{ .key = "odin", .source = "main :: proc(){}" },
.{ .key = "hare", .source = "export fn main() void;" },
.{ .key = "pony", .source = "actor Main" },
.{ .key = "tablegen", .source = "" },
.{ .key = "luadoc", .source = "" },
.{ .key = "puppet", .source = "$a=1" },
.{ .key = "luau", .source = "x=1" },
.{ .key = "objc", .source = "int a;" },
.{ .key = "ispc", .source = "int a;" },
.{ .key = "pem", .source = "" },
.{ .key = "requirements", .source = "a" },
.{ .key = "gpg", .source = "" },
.{ .key = "bb", .source = "A = \"1\"" },
.{ .key = "csv", .source = "a,b" },
.{ .key = "psv", .source = "a|b" },
.{ .key = "tsv", .source = "a\tb" },
.{ .key = "printf", .source = "" },
.{ .key = "re2c", .source = "" },
.{ .key = "doxygen", .source = "" },
.{ .key = "ssh_config", .source = "Host *" },
.{ .key = "nqc", .source = "" },
.{ .key = "kconfig", .source = "mainmenu \"x\"" },
.{ .key = "gn", .source = "executable(\"a\") {}" },
.{ .key = "udev", .source = "" },
.{ .key = "xcompose", .source = "" },
.{ .key = "linkerscript", .source = "" },
.{ .key = "properties", .source = "key=value" },
.{ .key = "readline", .source = "" },
.{ .key = "Makefile", .source = "x=a" },
.{ .key = "yaml", .source = "a: 1" },
.{ .key = "toml", .source = "a=1" },
.{ .key = "svelte", .source = "" },
.{ .key = "scss", .source = "$a:1" },
.{ .key = "cst", .source = "" },
.{ .key = "jl", .source = "x=1" },
.{ .key = "hs", .source = "x=1" },
.{ .key = "cyberchef", .source = "" },
.{ .key = "js", .source = "1" },
.{ .key = "json", .source = "1" },
.{ .key = "cpp", .source = "int a;" },
.{ .key = "rb", .source = "x=1" },
.{ .key = "go", .source = "package p" },
.{ .key = "cs", .source = "class A{}" },
.{ .key = "py", .source = "x=1" },
.{ .key = "rs", .source = "fn f(){}" },
.{ .key = "sh", .source = "true" },
.{ .key = "java", .source = "class A{}" },
.{ .key = "scala", .source = "class A" },
.{ .key = "agda", .source = "" },
.{ .key = "html", .source = "<p>" },
.{ .key = "embedded_template", .source = "" },
.{ .key = "regex", .source = "a" },
.{ .key = "css", .source = "a{}" },
.{ .key = "jsdoc", .source = "/** */" },
.{ .key = "ql", .source = "" },
};
comptime {
@setEvalBranchQuota(30000);
for (parse_entries) |e| {
if (!grammars.languages.has(e.key)) @compileError("unknown lang: " ++ e.key);
}
for (query_entries) |e| {
if (!queries_mod.queries.has(e.key)) @compileError("unknown query: " ++ e.key);
}
}
test "parse all languages" {
try runParseTest(parse_entries);
}
test "execute highlight queries" {
try runQueryTest(query_entries);
}

225
src/third_party_tests.zig Normal file
View file

@ -0,0 +1,225 @@
const std = @import("std");
const testing = std.testing;
const ts = @import("tree-sitter");
const ezts = @import("eazy_zig_tree_sitter");
const grammars = @import("grammars");
const Entry = struct { key: []const u8, source: []const u8 };
fn runParseTest(entries: []const Entry) !void {
for (entries) |e| {
const lang = ezts.getLang(e.key) orelse @panic("unknown lang");
defer lang.destroy();
var parser = ts.Parser.create();
defer parser.destroy();
try parser.setLanguage(lang);
const tree = parser.parseString(e.source, null) orelse {
std.debug.print("PARSE FAIL: {s}\n", .{e.key});
return error.ParseFailed;
};
defer tree.destroy();
}
}
const parse_entries: []const Entry = &.{
.{ .key = "ada", .source = "" },
.{ .key = "angular", .source = "" },
.{ .key = "apex", .source = "" },
.{ .key = "asm", .source = "" },
.{ .key = "astro", .source = "" },
.{ .key = "authzed", .source = "" },
.{ .key = "awk", .source = "1" },
.{ .key = "bass", .source = "" },
.{ .key = "beancount", .source = "" },
.{ .key = "bibtex", .source = "" },
.{ .key = "blade", .source = "" },
.{ .key = "bp", .source = "" },
.{ .key = "brightscript", .source = "" },
.{ .key = "caddy", .source = "" },
.{ .key = "circom", .source = "" },
.{ .key = "clojure", .source = "1" },
.{ .key = "cmake", .source = "" },
.{ .key = "comment", .source = "" },
.{ .key = "cooklang", .source = "" },
.{ .key = "corn", .source = "" },
.{ .key = "cue", .source = "" },
.{ .key = "cylc", .source = "" },
.{ .key = "d", .source = "1" },
.{ .key = "dart", .source = "1" },
.{ .key = "desktop", .source = "" },
.{ .key = "dhall", .source = "" },
.{ .key = "disassembly", .source = "" },
.{ .key = "djot", .source = "" },
.{ .key = "Dockerfile", .source = "FROM a" },
.{ .key = "dot", .source = "" },
.{ .key = "earthfile", .source = "" },
.{ .key = "ebnf", .source = "" },
.{ .key = "editorconfig", .source = "" },
.{ .key = "eds", .source = "" },
.{ .key = "eex", .source = "" },
.{ .key = "ex", .source = "1" },
.{ .key = "elm", .source = "1" },
.{ .key = "elsa", .source = "" },
.{ .key = "elvish", .source = "" },
.{ .key = "enforce", .source = "" },
.{ .key = "erl", .source = "1" },
.{ .key = "facility", .source = "" },
.{ .key = "faust", .source = "" },
.{ .key = "fennel", .source = "1" },
.{ .key = "fidl", .source = "" },
.{ .key = "fish", .source = "1" },
.{ .key = "foam", .source = "" },
.{ .key = "forth", .source = "" },
.{ .key = "f90", .source = "end" },
.{ .key = "fsh", .source = "" },
.{ .key = "fs", .source = "1" },
.{ .key = "gap", .source = "" },
.{ .key = "gaptst", .source = "" },
.{ .key = "gdshader", .source = "" },
.{ .key = "git_config", .source = "" },
.{ .key = "git_rebase", .source = "" },
.{ .key = "gitattributes", .source = "" },
.{ .key = "gitcommit", .source = "" },
.{ .key = "gitignore", .source = "" },
.{ .key = "gleam", .source = "1" },
.{ .key = "glimmer", .source = "" },
.{ .key = "glimmer_javascript", .source = "" },
.{ .key = "glimmer_typescript", .source = "" },
.{ .key = "gnuplot", .source = "" },
.{ .key = "goctl", .source = "" },
.{ .key = "godot_resource", .source = "" },
.{ .key = "gomod", .source = "module m" },
.{ .key = "gowork", .source = "go 1.20" },
.{ .key = "gql", .source = "{a}" },
.{ .key = "gren", .source = "" },
.{ .key = "groovy", .source = "1+1" },
.{ .key = "hh", .source = "<?hh" },
.{ .key = "haskell_persistent", .source = "" },
.{ .key = "heex", .source = "<p>1" },
.{ .key = "hjson", .source = "{a:1}" },
.{ .key = "hocon", .source = "{a=1}" },
.{ .key = "hoon", .source = "" },
.{ .key = "htmldjango", .source = "{{1}}" },
.{ .key = "http", .source = "GET /" },
.{ .key = "hurl", .source = "" },
.{ .key = "idl", .source = "" },
.{ .key = "idris", .source = "1+1" },
.{ .key = "ini", .source = "k=v" },
.{ .key = "inko", .source = "" },
.{ .key = "janet_simple", .source = "1" },
.{ .key = "javadoc", .source = "@param" },
.{ .key = "jinja", .source = "{{1}}" },
.{ .key = "jinja_inline", .source = "{{1}}" },
.{ .key = "jq", .source = "." },
.{ .key = "json5", .source = "{a:1}" },
.{ .key = "jsonnet", .source = "{}" },
.{ .key = "just", .source = "a:" },
.{ .key = "kcl", .source = "" },
.{ .key = "koto", .source = "" },
.{ .key = "kusto", .source = "T|take 1" },
.{ .key = "lalrpop", .source = "" },
.{ .key = "ledger", .source = "2024-01-01" },
.{ .key = "leo", .source = "" },
.{ .key = "liquid", .source = "{{1}}" },
.{ .key = "liquidsoap", .source = "" },
.{ .key = "llvm", .source = "i32 0" },
.{ .key = "m68k", .source = "" },
.{ .key = "menhir", .source = "" },
.{ .key = "mermaid", .source = "A-->B" },
.{ .key = "mlir", .source = "module {" },
.{ .key = "nasm", .source = "mov ax,1" },
.{ .key = "nginx", .source = "server{}" },
.{ .key = "nickel", .source = "" },
.{ .key = "nim", .source = "echo 1" },
.{ .key = "nim_format_string", .source = "" },
.{ .key = "ninja", .source = "rule a" },
.{ .key = "nix", .source = "{}" },
.{ .key = "norg", .source = "" },
.{ .key = "nu", .source = "1" },
.{ .key = "objdump", .source = "" },
.{ .key = "ocamllex", .source = "" },
.{ .key = "pascal", .source = "begin end" },
.{ .key = "passwd", .source = "root:x:0:" },
.{ .key = "phpdoc", .source = "@param" },
.{ .key = "pioasm", .source = "" },
.{ .key = "ps1", .source = "1+1" },
.{ .key = "prisma", .source = "model A{}" },
.{ .key = "problog", .source = "" },
.{ .key = "prolog", .source = "X=1" },
.{ .key = "promql", .source = "up" },
.{ .key = "proto", .source = "syntax" },
.{ .key = "prql", .source = "" },
.{ .key = "pug", .source = "p" },
.{ .key = "purescript", .source = "" },
.{ .key = "qmljs", .source = "" },
.{ .key = "r", .source = "1" },
.{ .key = "racket", .source = "x" },
.{ .key = "ralph", .source = "" },
.{ .key = "rasi", .source = "" },
.{ .key = "razor", .source = "@{}" },
.{ .key = "rbs", .source = "" },
.{ .key = "rego", .source = "package p" },
.{ .key = "rescript", .source = "" },
.{ .key = "rnoweb", .source = "" },
.{ .key = "robot", .source = "" },
.{ .key = "robots", .source = "" },
.{ .key = "roc", .source = "" },
.{ .key = "rst", .source = ".. " },
.{ .key = "scfg", .source = "" },
.{ .key = "scm", .source = "#t" },
.{ .key = "sflog", .source = "" },
.{ .key = "slim", .source = "" },
.{ .key = "slint", .source = "" },
.{ .key = "smithy", .source = "" },
.{ .key = "snakemake", .source = "" },
.{ .key = "solidity", .source = "pragma" },
.{ .key = "soql", .source = "" },
.{ .key = "sosl", .source = "" },
.{ .key = "sourcepawn", .source = "" },
.{ .key = "sparql", .source = "" },
.{ .key = "strace", .source = "" },
.{ .key = "styled", .source = "" },
.{ .key = "supercollider", .source = "" },
.{ .key = "surface", .source = "" },
.{ .key = "sway", .source = "" },
.{ .key = "sxhkdrc", .source = "" },
.{ .key = "systemtap", .source = "" },
.{ .key = "tact", .source = "" },
.{ .key = "templ", .source = "" },
.{ .key = "tera", .source = "" },
.{ .key = "textproto", .source = "" },
.{ .key = "tiger", .source = "" },
.{ .key = "tlaplus", .source = "" },
.{ .key = "todotxt", .source = "" },
.{ .key = "turtle", .source = "" },
.{ .key = "twig", .source = "" },
.{ .key = "typespec", .source = "" },
.{ .key = "typoscript", .source = "" },
.{ .key = "typst", .source = "" },
.{ .key = "unison", .source = "" },
.{ .key = "usd", .source = "" },
.{ .key = "v", .source = "1" },
.{ .key = "vala", .source = "" },
.{ .key = "vento", .source = "" },
.{ .key = "v", .source = "module" },
.{ .key = "vhdl", .source = "entity" },
.{ .key = "vhs", .source = "" },
.{ .key = "vimdoc", .source = "" },
.{ .key = "vrl", .source = "" },
.{ .key = "wgsl", .source = "" },
.{ .key = "wing", .source = "" },
.{ .key = "wit", .source = "" },
.{ .key = "xresources", .source = "" },
.{ .key = "yang", .source = "" },
};
comptime {
@setEvalBranchQuota(50000);
for (parse_entries) |e| {
if (!grammars.languages.has(e.key)) @compileError("unknown lang: " ++ e.key);
}
}
test "parse third-party languages" {
try runParseTest(parse_entries);
}