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 // The mapping is the `opens` annotations of `roles/lua.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!(lua);
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::lua::opens_space(node, code, ancestors)
18 }
19
20 keyword_roles!(lua);
21
22 paying_roles!(lua);
23
24 fn get_op_type<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> TokenRole {
25 match node.kind_id().into() {
26 // Control-flow keywords. `local` and `function` are not
27 // here: `roles/lua.rs` declares them and `get_keyword_role`
28 // bills them (#1693).
29 Lua::If
30 | Lua::Then
31 | Lua::Else
32 | Lua::Elseif
33 | Lua::End2
34 | Lua::For
35 | Lua::In
36 | Lua::While
37 | Lua::Do
38 | Lua::Repeat
39 | Lua::Until
40 | Lua::Return
41 | Lua::Goto
42 // `not`; `and` / `or` are the `ShortCircuit` row's and
43 // `get_paying_role` bills them (#1695)
44 | Lua::Not
45 // Structural punctuation. Only the *opening* delimiter is an
46 // operator: `get_operator_id_as_str` folds `LPAREN`/`LBRACK`/
47 // `LBRACE` to the pair glyph `()`/`[]`/`{}`, so a balanced pair
48 // is one operator with one occurrence — the convention the
49 // C-family majority follows. Counting the matching closer too
50 // (the former `RPAREN`/`RBRACK`/`RBRACE` arms) double-counted
51 // every balanced pair, inflating n1 and N1 (#695).
52 | Lua::SEMI
53 | Lua::COMMA
54 | Lua::COLON
55 | Lua::COLONCOLON
56 | Lua::LBRACE
57 | Lua::LBRACK
58 | Lua::LPAREN
59 | Lua::DOT
60 | Lua::DOTDOT
61 // Arithmetic / concat / length
62 | Lua::PLUS
63 | Lua::DASH
64 | Lua::STAR
65 | Lua::SLASH
66 | Lua::SLASHSLASH
67 | Lua::PERCENT
68 | Lua::CARET
69 | Lua::HASH
70 // Bitwise (Lua 5.3+)
71 | Lua::AMP
72 | Lua::PIPE
73 | Lua::TILDE
74 | Lua::LTLT
75 | Lua::GTGT
76 // `<` / `>` for the spelling the `Comparison` row's parent
77 // gate leaves out — a token error recovery strands — which
78 // billed before the row existed; the other comparison tokens
79 // are the row's and `get_paying_role` bills them (#1695).
80 // role-bypass: allow(Comparison) — the operator classification of the spelling the
81 // row's `under BinaryExpression` gate leaves out: a recovered token
82 | Lua::LT
83 | Lua::GT
84 // Assignment
85 | Lua::EQ
86 // `break` is a named leaf node (no anonymous keyword child), so it must be
87 // matched directly here — unlike `return`/`goto` which are anonymous tokens.
88 | Lua::BreakStatement => TokenRole::Operator,
89
90 // Operands: identifiers and literals
91 // role-bypass: allow(StringLit) — the operand classification of the literals,
92 // a projection the `StringLit` row does not answer
93 Lua::Identifier | Lua::Number | Lua::String | Lua::True | Lua::False | Lua::Nil
94 | Lua::VarargExpression => TokenRole::Operand,
95
96 _ => TokenRole::Unknown,
97 }
98 }
99
100 get_operator!(Lua);
101}