big_code_analysis_ast/getter/lua.rs
1//! `Getter` implementation for Lua.
2#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
3
4use super::*;
5
6impl Getter for LuaCode {
7 fn get_space_kind(node: &Node) -> SpaceKind {
8 match node.kind_id().into() {
9 Lua::FunctionDeclaration
10 | Lua::FunctionDeclaration2
11 | Lua::FunctionDeclaration3
12 | Lua::FunctionDefinition => SpaceKind::Function,
13 Lua::Chunk => SpaceKind::Unit,
14 _ => SpaceKind::Unknown,
15 }
16 }
17
18 fn get_op_type<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> TokenRole {
19 match node.kind_id().into() {
20 // Control-flow and declaration keywords
21 Lua::If
22 | Lua::Then
23 | Lua::Else
24 | Lua::Elseif
25 | Lua::End2
26 | Lua::For
27 | Lua::In
28 | Lua::While
29 | Lua::Do
30 | Lua::Repeat
31 | Lua::Until
32 | Lua::Return
33 | Lua::Goto
34 | Lua::Local
35 | Lua::Function
36 // Logical operators (keywords in Lua)
37 | Lua::And
38 | Lua::Or
39 | Lua::Not
40 // Structural punctuation. Only the *opening* delimiter is an
41 // operator: `get_operator_id_as_str` folds `LPAREN`/`LBRACK`/
42 // `LBRACE` to the pair glyph `()`/`[]`/`{}`, so a balanced pair
43 // is one operator with one occurrence — the convention the
44 // C-family majority follows. Counting the matching closer too
45 // (the former `RPAREN`/`RBRACK`/`RBRACE` arms) double-counted
46 // every balanced pair, inflating n1 and N1 (#695).
47 | Lua::SEMI
48 | Lua::COMMA
49 | Lua::COLON
50 | Lua::COLONCOLON
51 | Lua::LBRACE
52 | Lua::LBRACK
53 | Lua::LPAREN
54 | Lua::DOT
55 | Lua::DOTDOT
56 // Arithmetic / concat / length
57 | Lua::PLUS
58 | Lua::DASH
59 | Lua::STAR
60 | Lua::SLASH
61 | Lua::SLASHSLASH
62 | Lua::PERCENT
63 | Lua::CARET
64 | Lua::HASH
65 // Bitwise (Lua 5.3+)
66 | Lua::AMP
67 | Lua::PIPE
68 | Lua::TILDE
69 | Lua::LTLT
70 | Lua::GTGT
71 // Comparison
72 | Lua::EQEQ
73 | Lua::TILDEEQ
74 | Lua::LT
75 | Lua::GT
76 | Lua::LTEQ
77 | Lua::GTEQ
78 // Assignment
79 | Lua::EQ
80 // `break` is a named leaf node (no anonymous keyword child), so it must be
81 // matched directly here — unlike `return`/`goto` which are anonymous tokens.
82 | Lua::BreakStatement => TokenRole::Operator,
83
84 // Operands: identifiers and literals
85 Lua::Identifier | Lua::Number | Lua::String | Lua::True | Lua::False | Lua::Nil
86 | Lua::VarargExpression => TokenRole::Operand,
87
88 _ => TokenRole::Unknown,
89 }
90 }
91
92 get_operator!(Lua);
93}