luau_parser/types/
literals.rs

1//! Helper types for literal values.
2
3use std::num::{ParseFloatError, ParseIntError};
4
5/// An enum representing the return type of [`Number::parse`]..
6#[derive(Clone, Debug, PartialEq, PartialOrd)]
7#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
8pub enum ParsedNumber {
9    /// A hex or byte, the Roblox' maximum number is [`i64`]. But users may input
10    /// larger numbers, and for comparison, in linters for example, that maximum would be
11    /// stored as a [`i128`], which is why that is the type used here.
12    HexOrByte(i128),
13
14    /// Other numbers in Roblox can go up to 2^53 which is covered well by the [`f64`]
15    /// type, it's also used as these "other" numbers can have decimals in them.
16    Other(f64),
17}
18
19/// An enum representing errors that can occur during [`Number::parse`] stopping it from
20/// parsing the number, they should only be out-of-range errors and thus should be
21/// displayed for the user asking them to change the number.
22#[derive(Clone, Debug, PartialEq, Eq)]
23pub enum ParseNumberError {
24    /// Hexadecimal and binary numbers are always integers.
25    HexOrByte(ParseIntError),
26
27    /// Other numbers in Roblox are stored as floats.
28    Other(ParseFloatError),
29}