big-code-analysis-ast 2.6.0

Parse and classification layer behind big-code-analysis (internal, version-locked)
Documentation
//! `Checker` implementation for Go.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]

use super::*;

impl Checker for GoCode {
    // The `Comment`, `DocTarget` and `DocRunDirective` rows of
    // `roles/go.rs` (#1699): go/doc's targets under the function-body
    // scope gate, read with the node's own chain; a directive by its
    // bytes.
    impl_comment_from_rows!(go);

    impl_doc_target_from_row!(go);

    impl_doc_run_directive_from_row!(go);

    // The space tree is declared in `roles/go.rs` (#1696): the
    // `FuncOpener` and `Container` rows are what the walk promotes and
    // `opens_space` labels. The rows read no bytes and no chain, so the
    // byte-less spelling forwards with none and answers the same.
    impl_byte_less_func_space!(go);

    fn is_func_space_with_code<'a>(
        node: &Node<'a>,
        code: &[u8],
        ancestors: Ancestors<'a, '_>,
    ) -> bool {
        crate::roles::go::opens_space(node, code, ancestors) != SpaceKind::Unknown
    }

    fn is_func_with_code<'a>(node: &Node<'a>, code: &[u8], ancestors: Ancestors<'a, '_>) -> bool {
        crate::roles::go::func_opener::is_callable(node, code, ancestors)
    }

    fn is_closure<'a>(node: &Node<'a>, ancestors: Ancestors<'a, '_>) -> bool {
        crate::roles::go::closure::owns(node, &[], ancestors)
    }

    // `Call` and `StringLit` are the rows of `roles/go.rs` (#1698);
    // the byte-less spellings are their kind tables, gates aside.
    impl_row_predicates!(go, call, is_call, is_call_with_code);
    impl_row_predicates!(go, string_lit, is_string, is_string_with_code);

    // No `is_non_arg`: `impl NArgs for GoCode` counts by declaration
    // kind (`compute_go_args`), so the trait's negative filter is never
    // consulted and the default `false` stands.

    // The `ElseIf` row of `roles/go.rs`: an `if_statement` whose parent
    // is the outer `if_statement` (the grammar has no else clause node),
    // read off the caller's chain. The row reads no bytes (#1697).
    impl_else_if_from_row!(go);
}