"""Language data for tree-sitter code chunking.

tree-sitter-language-pack provides only ``get_parser(language_name)`` — it has no
extension-to-language mapping or per-language definition-type metadata. These dicts
must be maintained manually when adding support for new languages.
"""

# Extension -> tree-sitter language name.
# Languages without DEFINITION_TYPES entries fall back to token-based chunking.
EXT_TO_LANG: dict[str, str] = {
    # Systems / compiled
    ".c": "c",
    ".h": "c",
    ".cpp": "cpp",
    ".cxx": "cpp",
    ".cc": "cpp",
    ".hpp": "cpp",
    ".hxx": "cpp",
    ".cs": "csharp",
    ".d": "d",
    ".go": "go",
    ".java": "java",
    ".kt": "kotlin",
    ".kts": "kotlin",
    ".m": "objc",
    ".rs": "rust",
    ".scala": "scala",
    ".swift": "swift",
    ".zig": "zig",
    ".v": "v",
    ".odin": "odin",
    ".hare": "hare",
    ".nim": "nim",
    ".ada": "ada",
    ".adb": "ada",
    ".ads": "ada",
    ".f90": "fortran",
    ".f95": "fortran",
    ".f03": "fortran",
    ".f": "fortran",
    ".pas": "pascal",
    ".cobol": "cobol",
    ".cob": "cobol",
    ".cbl": "cobol",
    ".vhdl": "vhdl",
    ".vhd": "vhdl",
    ".sv": "verilog",
    ".svh": "verilog",
    ".verilog": "verilog",
    # Scripting / dynamic
    ".py": "python",
    ".pyi": "python",
    ".js": "javascript",
    ".jsx": "javascript",
    ".mjs": "javascript",
    ".cjs": "javascript",
    ".ts": "typescript",
    ".tsx": "tsx",
    ".rb": "ruby",
    ".php": "php",
    ".lua": "lua",
    ".luau": "luau",
    ".pl": "perl",
    ".pm": "perl",
    ".r": "r",
    ".R": "r",
    ".jl": "julia",
    ".ex": "elixir",
    ".exs": "elixir",
    ".erl": "erlang",
    ".hrl": "erlang",
    ".clj": "clojure",
    ".cljs": "clojure",
    ".cljc": "clojure",
    ".ml": "ocaml",
    ".mli": "ocaml_interface",
    ".hs": "haskell",
    ".fs": "fsharp",
    ".fsi": "fsharp_signature",
    ".fsx": "fsharp",
    ".elm": "elm",
    ".purs": "purescript",
    ".rkt": "racket",
    ".scm": "scheme",
    ".el": "elisp",
    ".lisp": "commonlisp",
    ".cl": "commonlisp",
    ".fnl": "fennel",
    ".janet": "janet",
    ".dart": "dart",
    ".gd": "gdscript",
    ".gleam": "gleam",
    ".groovy": "groovy",
    ".gradle": "groovy",
    ".tcl": "tcl",
    ".fish": "fish",
    ".ps1": "powershell",
    ".psm1": "powershell",
    ".psd1": "powershell",
    ".matlab": "matlab",
    ".pony": "pony",
    ".hack": "hack",
    ".hx": "haxe",
    ".squirrel": "squirrel",
    ".nut": "squirrel",
    ".nix": "nix",
    ".star": "starlark",
    ".bzl": "starlark",
    ".smali": "smali",
    # Shell
    ".sh": "bash",
    ".bash": "bash",
    ".zsh": "bash",
    # Web / markup
    ".html": "html",
    ".htm": "html",
    ".xml": "xml",
    ".xsl": "xml",
    ".xslt": "xml",
    ".css": "css",
    ".scss": "scss",
    ".vue": "vue",
    ".svelte": "svelte",
    ".astro": "astro",
    ".twig": "twig",
    ".md": "markdown",
    ".markdown": "markdown",
    # Functional / blockchain / smart contracts
    ".sol": "solidity",
    ".cairo": "cairo",
    ".fc": "func",
    ".clar": "clarity",
    ".rego": "rego",
    # Data / config
    ".json": "json",
    ".jsonnet": "jsonnet",
    ".libsonnet": "jsonnet",
    ".yaml": "yaml",
    ".yml": "yaml",
    ".toml": "toml",
    ".ini": "ini",
    ".cfg": "ini",
    ".properties": "properties",
    ".ron": "ron",
    ".kdl": "kdl",
    ".hcl": "hcl",
    ".tf": "terraform",
    ".tfvars": "terraform",
    ".graphql": "graphql",
    ".gql": "graphql",
    ".proto": "proto",
    ".thrift": "thrift",
    ".capnp": "capnp",
    ".smithy": "smithy",
    ".prisma": "prisma",
    ".beancount": "beancount",
    ".sql": "sql",
    ".sparql": "sparql",
    # Build / CI
    ".cmake": "cmake",
    ".ninja": "ninja",
    ".meson": "meson",
    ".gn": "gn",
    ".pp": "puppet",
    ".tex": "latex",
    ".bib": "bibtex",
    ".typst": "typst",
    # HDL / embedded
    ".cuda": "cuda",
    ".cu": "cuda",
    ".glsl": "glsl",
    ".hlsl": "hlsl",
    ".wgsl": "wgsl",
    ".ispc": "ispc",
    ".s": "asm",
    ".asm": "asm",
    ".ll": "llvm",
    ".lds": "linkerscript",
    ".wat": "wat",
    ".wast": "wast",
    # Docker / infra
    ".dockerfile": "dockerfile",
    ".bicep": "bicep",
}

# AST node types that represent extractable definitions, per language.
DEFINITION_TYPES: dict[str, frozenset[str]] = {
    "python": frozenset(
        {
            "function_definition",
            "class_definition",
            "decorated_definition",
        }
    ),
    "javascript": frozenset(
        {
            "function_declaration",
            "class_declaration",
            "export_statement",
            "lexical_declaration",
        }
    ),
    "typescript": frozenset(
        {
            "function_declaration",
            "class_declaration",
            "export_statement",
            "lexical_declaration",
            "interface_declaration",
            "type_alias_declaration",
        }
    ),
    "go": frozenset(
        {
            "function_declaration",
            "method_declaration",
            "type_declaration",
        }
    ),
    "rust": frozenset(
        {
            "function_item",
            "impl_item",
            "struct_item",
            "enum_item",
            "trait_item",
        }
    ),
    "java": frozenset(
        {
            "class_declaration",
            "method_declaration",
            "interface_declaration",
        }
    ),
    "c": frozenset({"function_definition", "struct_specifier"}),
    "cpp": frozenset(
        {
            "function_definition",
            "class_specifier",
            "struct_specifier",
        }
    ),
    "ruby": frozenset({"method", "class", "module", "singleton_method"}),
    "php": frozenset({"function_definition", "class_declaration", "method_declaration"}),
    "csharp": frozenset({"method_declaration", "class_declaration", "interface_declaration"}),
    "bash": frozenset({"function_definition"}),
    "kotlin": frozenset({"function_declaration", "class_declaration", "object_declaration"}),
    "swift": frozenset({"function_declaration", "class_declaration", "protocol_declaration"}),
    "scala": frozenset(
        {"function_definition", "class_definition", "object_definition", "trait_definition"}
    ),
    "lua": frozenset({"function_declaration", "function_definition_statement"}),
    "elixir": frozenset({"call"}),
    "haskell": frozenset({"function", "type_alias", "newtype", "adt"}),
    "dart": frozenset({"function_signature", "class_definition", "method_signature"}),
    "ocaml": frozenset({"let_binding", "type_definition", "module_binding"}),
    "erlang": frozenset({"function_clause"}),
    "clojure": frozenset({"list_lit"}),
    "elm": frozenset({"function_declaration_left", "type_alias_declaration", "type_declaration"}),
    "julia": frozenset({"function_definition", "struct_definition", "module_definition"}),
    "r": frozenset({"function_definition"}),
    "perl": frozenset({"function_definition"}),
    "groovy": frozenset({"function_definition", "class_definition", "method_declaration"}),
    "fortran": frozenset({"function", "subroutine", "module"}),
    "pascal": frozenset({"function_declaration", "procedure_declaration"}),
    "d": frozenset({"function_declaration", "class_declaration", "struct_declaration"}),
    "nim": frozenset({"proc_declaration", "func_declaration", "type_section"}),
    "zig": frozenset({"function_declaration"}),
    "v": frozenset({"function_declaration", "struct_declaration"}),
    "odin": frozenset({"procedure_declaration"}),
    "solidity": frozenset({"function_definition", "contract_declaration"}),
    "terraform": frozenset({"block"}),
    "sql": frozenset({"create_function_statement", "create_table_statement"}),
    "objc": frozenset({"function_definition", "class_interface", "class_implementation"}),
    "cuda": frozenset({"function_definition", "struct_specifier"}),
    "fsharp": frozenset({"function_or_value_defn", "type_definition", "module_defn"}),
}
