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
//! Faithful port of Luau `Lexeme` (`Ast/include/Luau/Lexer.h`).
//!
//! The token payload is a C++ union (`const char* data`/`name`, `unsigned
//! codepoint`); a Rust `union` reproduces it. Unions can derive `Clone`/`Copy`
//! but not `Debug`, so `LexemeData` gets a hand-written `Debug` (it can't know
//! which arm is active) and `Lexeme` then derives `Debug` normally.
pub use crate::enums::type_lexer::Type;
use crate::records::location::Location;
/// `Lexeme::QuoteStyle` (`Ast/include/Luau/Lexer.h`) — the delimiter of a quoted
/// string token, returned by `get_quote_style`.
#[allow(non_camel_case_types)]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum QuoteStyle {
Single,
Double,
}
#[allow(non_snake_case)]
#[derive(Debug, Clone, Copy)]
pub struct Lexeme {
pub r#type: Type,
pub location: Location,
pub(crate) length: u32,
pub data: LexemeData,
}
#[derive(Clone, Copy)]
#[repr(C)]
pub union LexemeData {
pub data: *const core::ffi::c_char,
pub name: *const core::ffi::c_char,
pub codepoint: u32,
}
impl core::fmt::Debug for LexemeData {
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
// The active arm is determined by `Lexeme::type`; print opaquely.
f.write_str("LexemeData(..)")
}
}
impl Default for LexemeData {
fn default() -> Self {
Self {
data: core::ptr::null(),
}
}
}