// Generated by tools/grammars/update.sh. Do not edit.
//
// The equivalent of bindings/rust/lib.rs of tree-sitter/tree-sitter-php v0.24.2:
// the languages of the grammar (`LanguageFn` constants there) as functions
// returning a `@treesitter.Language`, decoded on first use; the string
// constants (queries, node types) are in the other files of the package.

///|
let language_php_cache : Ref[@treesitter.Language?] = Ref(None)

///|
/// The tree-sitter language for `php` (`LANGUAGE_PHP` in the Rust binding),
/// generated from `php/src/grammar.json`. Its external scanner is
/// `@scanners.scanner_for("php")`; without one (a scanner not ported yet) the
/// language is not parseable (`@treesitter.Language::is_parseable`).
pub fn language_php() -> @treesitter.Language {
  load(language_php_cache, language_php_tables)
}

///|
let language_php_only_cache : Ref[@treesitter.Language?] = Ref(None)

///|
/// The tree-sitter language for `php_only` (`LANGUAGE_PHP_ONLY` in the Rust
/// binding), generated from `php_only/src/grammar.json`. Its external scanner
/// is `@scanners.scanner_for("php_only")`; without one (a scanner not ported
/// yet) the language is not parseable (`@treesitter.Language::is_parseable`).
pub fn language_php_only() -> @treesitter.Language {
  load(language_php_only_cache, language_php_only_tables)
}

///|
fn load(
  cache : Ref[@treesitter.Language?],
  tables : String,
) -> @treesitter.Language {
  if cache.val is Some(language) {
    return language
  }
  let raw = @language.Language::from_compact_base64(tables) catch {
    e => abort(e.to_string())
  }
  let language = if raw.external_token_count > 0 {
    @treesitter.Language::new(
      raw,
      external_scanner?=@scanners.scanner_for(raw.name),
    )
  } else {
    @treesitter.Language::new(raw)
  }
  cache.val = Some(language)
  language
}