Skip to main content

big_code_analysis_ast/getter/
go.rs

1//! `Getter` implementation for Go.
2#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
3
4use super::*;
5
6impl Getter for GoCode {
7    // The mapping is the `opens` annotations of `roles/go.rs`
8    // (#1696). The rows read no bytes and no chain, so the byte-less
9    // spelling forwards with none.
10    impl_byte_less_space_kind!(go);
11
12    fn get_space_kind_with_code<'a>(
13        node: &Node<'a>,
14        code: &[u8],
15        ancestors: Ancestors<'a, '_>,
16    ) -> SpaceKind {
17        crate::roles::go::opens_space(node, code, ancestors)
18    }
19
20    keyword_roles!(go);
21
22    paying_roles!(go);
23
24    fn get_op_type<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> TokenRole {
25        use Go as G;
26
27        // The declaration keywords are not here: `roles/go.rs` declares
28        // them and `get_keyword_role` bills them (#1693).
29        match node.kind_id().into() {
30            // Control flow keywords and the `map` / `chan` type constructors
31            // `<` / `>` for the spelling the `Comparison` row's parent gate
32            // leaves out — a token error recovery strands — which billed
33            // before the row existed; the other comparison and
34            // short-circuit tokens are the rows' and `get_paying_role`
35            // bills them (#1695).
36            // role-bypass: allow(Comparison) — the operator classification of the spelling the row's
37            // `under BinaryExpression` gate leaves out: a recovered token
38            G::LT | G::GT
39            | G::If | G::Else | G::Switch | G::Case | G::Default | G::For | G::Range
40            | G::Continue | G::Break | G::Fallthrough | G::Goto | G::Return | G::Select
41            | G::Defer | G::Go | G::Map | G::Chan
42            // Punctuation acting as operators
43            | G::SEMI | G::COMMA | G::COLON | G::LBRACE | G::LBRACK | G::LPAREN
44            | G::DOT | G::DOTDOTDOT
45            // Operators
46            | G::EQ | G::COLONEQ | G::PLUS | G::DASH | G::STAR | G::SLASH | G::PERCENT
47            | G::AMP | G::PIPE | G::CARET | G::TILDE | G::BANG
48            | G::LTLT | G::GTGT | G::AMPCARET | G::LTDASH | G::PLUSPLUS | G::DASHDASH
49            | G::PLUSEQ | G::DASHEQ | G::STAREQ | G::SLASHEQ | G::PERCENTEQ | G::AMPEQ
50            | G::PIPEEQ | G::CARETEQ | G::LTLTEQ | G::GTGTEQ | G::AMPCARETEQ
51                => TokenRole::Operator,
52            // Operands: identifiers and literals
53            // role-bypass: allow(StringLit) — the operand classification of the literals,
54            // a projection the `StringLit` row does not answer
55            G::Identifier | G::Identifier2 | G::Identifier3 | G::BlankIdentifier
56            | G::FieldIdentifier | G::PackageIdentifier | G::TypeIdentifier
57            | G::LabelName | G::IntLiteral | G::FloatLiteral | G::ImaginaryLiteral
58            | G::RuneLiteral | G::InterpretedStringLiteral | G::RawStringLiteral | G::Nil
59            | G::True | G::False | G::Iota
60                => TokenRole::Operand,
61            _ => TokenRole::Unknown,
62        }
63    }
64
65    get_operator!(Go);
66}