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    fn get_space_kind(node: &Node) -> SpaceKind {
8        // Aliased because `Go::Go` (the `go` keyword variant) collides with
9        // the bare enum name in pattern position under `use Go::*;`.
10        use Go as G;
11
12        match node.kind_id().into() {
13            G::FunctionDeclaration | G::MethodDeclaration | G::FuncLiteral => SpaceKind::Function,
14            G::SourceFile => SpaceKind::Unit,
15            _ => SpaceKind::Unknown,
16        }
17    }
18
19    fn get_op_type<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> TokenRole {
20        use Go as G;
21
22        match node.kind_id().into() {
23            // Control flow and declaration keywords
24            G::If | G::Else | G::Switch | G::Case | G::Default | G::For | G::Range
25            | G::Continue | G::Break | G::Fallthrough | G::Goto | G::Return | G::Select
26            | G::Defer | G::Go | G::Func | G::Type | G::Struct | G::Interface | G::Map
27            | G::Chan | G::Const | G::Var | G::Package | G::Import
28            // Punctuation acting as operators
29            | G::SEMI | G::COMMA | G::COLON | G::LBRACE | G::LBRACK | G::LPAREN
30            | G::DOT | G::DOTDOTDOT
31            // Operators
32            | G::EQ | G::COLONEQ | G::PLUS | G::DASH | G::STAR | G::SLASH | G::PERCENT
33            | G::AMP | G::PIPE | G::CARET | G::TILDE | G::BANG | G::LT | G::GT
34            | G::LTEQ | G::GTEQ | G::EQEQ | G::BANGEQ | G::AMPAMP | G::PIPEPIPE
35            | G::LTLT | G::GTGT | G::AMPCARET | G::LTDASH | G::PLUSPLUS | G::DASHDASH
36            | G::PLUSEQ | G::DASHEQ | G::STAREQ | G::SLASHEQ | G::PERCENTEQ | G::AMPEQ
37            | G::PIPEEQ | G::CARETEQ | G::LTLTEQ | G::GTGTEQ | G::AMPCARETEQ
38                => TokenRole::Operator,
39            // Operands: identifiers and literals
40            G::Identifier | G::Identifier2 | G::Identifier3 | G::BlankIdentifier
41            | G::FieldIdentifier | G::PackageIdentifier | G::TypeIdentifier
42            | G::LabelName | G::IntLiteral | G::FloatLiteral | G::ImaginaryLiteral
43            | G::RuneLiteral | G::InterpretedStringLiteral | G::RawStringLiteral | G::Nil
44            | G::True | G::False | G::Iota
45                => TokenRole::Operand,
46            _ => TokenRole::Unknown,
47        }
48    }
49
50    get_operator!(Go);
51}