Skip to content

Commit d030f00

Browse files
committed
(lexer) fix: missing doc in private items
1 parent dd5a539 commit d030f00

File tree

20 files changed

+274
-32
lines changed

20 files changed

+274
-32
lines changed

src/errors/location.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,6 @@ impl Location {
6969
CompileError::from((self.to_owned(), msg, ErrorLevel::Error))
7070
}
7171

72-
/// Returns a clone of the current file name.
73-
pub(crate) fn to_filename(&self) -> String {
74-
self.file.clone()
75-
}
76-
7772
/// Creates an suggestion by cloning the location.
7873
pub(crate) fn to_suggestion(&self, msg: String) -> CompileError {
7974
CompileError::from((self.to_owned(), msg, ErrorLevel::Warning))

src/lexer/lex_content.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Module that implements the functions that lex raw strings.
2+
//!
3+
//! See [`lex_file`] for more information.
4+
15
#[allow(clippy::enum_glob_use)]
26
use LexingState::*;
37

@@ -7,6 +11,10 @@ use super::state::api::{
711
use super::types::api::{LexingData, Token};
812
use crate::errors::api::{Location, Res};
913

14+
/// Function to manage one character.
15+
///
16+
/// This function updates the [`LexingState`] automaton, and executes the right
17+
/// handlers.
1018
#[expect(clippy::too_many_lines)]
1119
fn lex_char(
1220
ch: char,
@@ -149,6 +157,10 @@ fn lex_char(
149157
}
150158
}
151159

160+
/// Function that lexes a whole source file.
161+
///
162+
/// This function creates the automaton and the data to be modified by the other
163+
/// functions. Every character is parsed one by one by [`lex_char`].
152164
#[inline]
153165
pub fn lex_file(content: &str, location: &mut Location) -> Res<Vec<Token>> {
154166
let mut lex_data = LexingData::default();
@@ -162,6 +174,10 @@ pub fn lex_file(content: &str, location: &mut Location) -> Res<Vec<Token>> {
162174
lex_data.into_res()
163175
}
164176

177+
/// Function that lexes one line.
178+
///
179+
/// It stops at the first erroneous character, or at the end of the line if
180+
/// everything was ok.
165181
fn lex_line(
166182
line: &str,
167183
location: &mut Location,

src/lexer/numbers/base/binary.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module to parse binary-represented number constants
2+
13
use super::super::macros::parse_int_from_radix;
24
use super::super::parse::OverParseRes;
35
#[allow(clippy::wildcard_imports)]

src/lexer/numbers/base/decimal.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module to parse decimal-represented number constants
2+
13
use core::num::ParseFloatError;
24
use core::str::FromStr;
35

@@ -7,6 +9,8 @@ use super::super::types::arch_types::*;
79
use super::super::types::{ERR_PREFIX, Number, NumberType};
810
use crate::errors::api::{CompileError, Location};
911

12+
/// Parses the stringifies version of a decimal number in a specific integer
13+
/// or floating point type.
1014
macro_rules! parse_number {
1115
($location:ident, $nb_type:ident, $literal:tt, $($int:ident)*, $($float:ident)*) => {
1216
match $nb_type {
@@ -17,6 +21,8 @@ macro_rules! parse_number {
1721
};
1822
}
1923

24+
/// Parses the stringifies version of decimal number in a specific floating
25+
/// point type.
2026
fn parse_and_error<T>(literal: &str, location: &Location) -> Result<T, CompileError>
2127
where
2228
T: FromStr,

src/lexer/numbers/base/hexadecimal.rs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module to parse hexadecimal-represented number constants
2+
13
#![allow(clippy::arbitrary_source_item_ordering)]
24

35
use super::super::macros::parse_int_from_radix;
@@ -7,13 +9,14 @@ use super::super::types::arch_types::*;
79
use super::super::types::{ERR_PREFIX, Number, NumberType};
810
use crate::errors::api::{CompileError, Location};
911

12+
/// Implements the [`FloatingPoint`] for the floating-point types.
1013
macro_rules! impl_floating_point {
11-
($x:expr, $($ftype:ident)*) => {
14+
($x:expr, $($type:ident)*) => {
1215
$(#[expect(clippy::as_conversions, clippy::cast_precision_loss)]
13-
impl FloatingPoint<concat_idents!($ftype, IntPart)> for $ftype {
16+
impl FloatingPoint<concat_idents!($type, IntPart)> for $type {
1417
const MANTISSA_SIZE: u32 = $x;
1518

16-
type Unsigned = concat_idents!($ftype, IntPart);
19+
type Unsigned = concat_idents!($type, IntPart);
1720

1821

1922
fn from_unsigned(
@@ -39,6 +42,7 @@ macro_rules! impl_floating_point {
3942
};
4043
}
4144

45+
/// Parses the stringified version of a number into a [`HexFloatData`].
4246
macro_rules! parse_hexadecimal_float {
4347
($overflow:expr, $nb_type:ident, $float_parse:ident, $($t:ident)*) => {{
4448
match $nb_type {
@@ -71,9 +75,17 @@ impl_floating_point!(23, Double Float LongDouble);
7175
///
7276
/// ``overflow`` is set to true if the value doesn't fix in the mantissa.
7377
trait FloatingPoint<T> {
78+
/// Size of the mantissa
79+
///
80+
/// In the binary representation of the floating-point
81+
/// values, there is one part for the exponent, and one point for the
82+
/// digits, the latter is called 'mantissa'.
7483
const MANTISSA_SIZE: u32;
84+
/// The biggest unsigned integer type that can contain the mantissa.
7585
type Unsigned;
86+
/// Convert the integer-parsed value into the current floating-point type.
7687
fn from_unsigned(val: T, overflow: &mut bool) -> Self;
88+
/// Convert the usize-parsed value into the current floating-point type.
7789
fn from_usize(val: usize, overflow: &mut bool) -> Self;
7890
}
7991

@@ -100,6 +112,7 @@ struct HexFloatData {
100112
}
101113

102114
impl HexFloatData {
115+
/// Pushes a character to the current state.
103116
fn push(&mut self, ch: char) {
104117
match self.state {
105118
HexFloatParseState::Int => self.int_part.push(ch),
@@ -108,6 +121,7 @@ impl HexFloatData {
108121
}
109122
}
110123

124+
/// Returns the exponent of the number constant.
111125
fn get_exp(&self) -> u32 {
112126
if self.exponent.is_empty() {
113127
0
@@ -125,8 +139,18 @@ impl HexFloatData {
125139
/// and a exponent part after an exponent character ('p').
126140
#[derive(Default, PartialEq, Eq, Debug)]
127141
enum HexFloatParseState {
142+
/// Decimal part
143+
///
144+
/// The part between the full stop and the exponent character 'p' (if they
145+
/// exist).
128146
Decimal,
147+
/// Exponent part
148+
///
149+
/// Last part of the string, after the 'p' character.
129150
Exponent,
151+
/// Integer part
152+
///
153+
/// First part of the string, before the full stop and the 'p' character.
130154
#[default]
131155
Int,
132156
}

src/lexer/numbers/base/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module to parse number constants, respectively to a base and a type.
2+
13
pub mod binary;
24
pub mod decimal;
35
pub mod hexadecimal;

src/lexer/numbers/base/octal.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Module to parse octal-represented number constants
2+
13
use super::super::macros::parse_int_from_radix;
24
use super::super::parse::OverParseRes;
35
#[allow(clippy::wildcard_imports)]

src/lexer/numbers/from_literal.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Module that tries to convert a string into a valid constant C number,
2+
//! whatever the size, type and encoding base.
3+
14
use core::str;
25

36
use super::super::types::api::{Ident, LexingData};

src/lexer/numbers/macros.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1+
//! Module that defines useful macros to parse integer and get useful errors.
2+
13
#![allow(clippy::arbitrary_source_item_ordering)]
24
#![allow(clippy::pub_use)]
35

6+
/// Parses an integer from a given base
7+
///
8+
/// Specify the base with the radix integer, that is 2, 8 or 16.
9+
///
10+
/// For base 10, please use [`safe_parse_int`] for better errors.
411
macro_rules! parse_int_from_radix {
512
($location:ident, $nb_type:ident, $literal:tt, $reason:expr, $radix:expr, $($t:ident)*) => {{
613
use $crate::lexer::numbers::{macros::safe_parse_int, parse::OverParseRes};
@@ -12,6 +19,7 @@ macro_rules! parse_int_from_radix {
1219
}};
1320
}
1421

22+
/// Parses an decimal integer from a string
1523
macro_rules! safe_parse_int {
1624
($err_prefix:expr, $dest_type:ident, $location:ident, $function_call:expr) => {{
1725
use $crate::lexer::numbers::api::OverParseRes;

src/lexer/numbers/parse.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Module that defines the result and error types used for parsing a number
2+
//! constant.
3+
14
use core::{convert, fmt, ops};
25

36
use super::types::Number;
@@ -12,10 +15,15 @@ use crate::errors::api::{CompileError, Location};
1215
/// If an error occurs, the overflows are ignored (overflows are only warnings
1316
/// not errors.)
1417
pub enum OverParseRes<T> {
18+
/// Number parsing failed
1519
Err(CompileError),
20+
/// Number parsing overflowed
1621
Overflow,
22+
/// Number parsing succeeded
1723
Value(T),
24+
/// Number parsing succeeded; but with a warning
1825
ValueErr(T, CompileError),
26+
/// Number parsing succeeded; but with an overflow
1927
ValueOverflow(T),
2028
}
2129

@@ -118,8 +126,11 @@ impl ops::FromResidual<Result<convert::Infallible, CompileError>> for OverParseR
118126
/// This is the equivalent of [`OverParseRes`], but were the overflows were
119127
/// transformed into warnings.
120128
pub enum ParseRes<T> {
129+
/// Number parsing failed
121130
Err(CompileError),
131+
/// Number parsing succeeded
122132
Value(T),
133+
/// Number parsing succeeded; but with a warning
123134
ValueErr(T, CompileError),
124135
}
125136

0 commit comments

Comments
 (0)