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