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
94
95
96
97
98
99
100
101
//! `Getter` implementation for Lua.
#![allow(clippy::wildcard_imports, clippy::enum_glob_use)]
use super::*;
impl Getter for LuaCode {
// The mapping is the `opens` annotations of `roles/lua.rs`
// (#1696). The rows read no bytes and no chain, so the byte-less
// spelling forwards with none.
impl_byte_less_space_kind!(lua);
fn get_space_kind_with_code<'a>(
node: &Node<'a>,
code: &[u8],
ancestors: Ancestors<'a, '_>,
) -> SpaceKind {
crate::roles::lua::opens_space(node, code, ancestors)
}
keyword_roles!(lua);
paying_roles!(lua);
fn get_op_type<'a>(node: &Node<'a>, _ancestors: Ancestors<'a, '_>) -> TokenRole {
match node.kind_id().into() {
// Control-flow keywords. `local` and `function` are not
// here: `roles/lua.rs` declares them and `get_keyword_role`
// bills them (#1693).
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
// `not`; `and` / `or` are the `ShortCircuit` row's and
// `get_paying_role` bills them (#1695)
| 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
// `<` / `>` for the spelling the `Comparison` row's parent
// gate leaves out — a token error recovery strands — which
// billed before the row existed; the other comparison tokens
// are the row's and `get_paying_role` bills them (#1695).
// role-bypass: allow(Comparison) — the operator classification of the spelling the
// row's `under BinaryExpression` gate leaves out: a recovered token
| Lua::LT
| Lua::GT
// 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 => TokenRole::Operator,
// Operands: identifiers and literals
// role-bypass: allow(StringLit) — the operand classification of the literals,
// a projection the `StringLit` row does not answer
Lua::Identifier | Lua::Number | Lua::String | Lua::True | Lua::False | Lua::Nil
| Lua::VarargExpression => TokenRole::Operand,
_ => TokenRole::Unknown,
}
}
get_operator!(Lua);
}