From bea8f047c7dd5b95ece27018d2a407e0e6c38b8c Mon Sep 17 00:00:00 2001 From: Venus Xeon-Blonde Date: Sat, 24 Feb 2024 04:04:19 -0500 Subject: [PATCH] fmt --- wright/src/bin/wright.rs | 2 +- wright/src/parser/fragment.rs | 10 +++++----- wright/src/parser/lexer.rs | 13 ++++++++----- wright/src/parser/lexer/token.rs | 4 ++-- wright/src/parser/lexer/trivial.rs | 28 ++++++++++++++++------------ 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/wright/src/bin/wright.rs b/wright/src/bin/wright.rs index 669a3afb..16e6ef90 100644 --- a/wright/src/bin/wright.rs +++ b/wright/src/bin/wright.rs @@ -6,7 +6,7 @@ use codespan_reporting::files::Files; use std::{path::PathBuf, time::Instant}; use wright::{ filemap::{FileId, FileMap}, - parser::lexer::{Lexer, token::Token}, + parser::lexer::{token::Token, Lexer}, repl, }; diff --git a/wright/src/parser/fragment.rs b/wright/src/parser/fragment.rs index 21ffa775..01b3eedf 100644 --- a/wright/src/parser/fragment.rs +++ b/wright/src/parser/fragment.rs @@ -68,13 +68,13 @@ impl<'src> Fragment<'src> { } /// Unsafe version of [`Fragment::split_at`]. Splits this [Fragment] into two subfragments, - /// where the left one contains the first `bytes` bytes of the fragment, and the right one - /// contains the rest. - /// + /// where the left one contains the first `bytes` bytes of the fragment, and the right one + /// contains the rest. + /// /// # Safety /// - Undefined Behavior occurs if `bytes` is greater than the length of the [Fragment]. - /// - Undefined Behavior occurs if `bytes` is not on a UTF-8 character boundary. - /// - See [str::get_unchecked] for more details. + /// - Undefined Behavior occurs if `bytes` is not on a UTF-8 character boundary. + /// - See [str::get_unchecked] for more details. pub unsafe fn split_at_unchecked(&self, bytes: usize) -> (Self, Self) { let left: &str = self.inner.get_unchecked(..bytes); let right: &str = self.inner.get_unchecked(bytes..); diff --git a/wright/src/parser/lexer.rs b/wright/src/parser/lexer.rs index 35f4e9a9..f7b8dc55 100644 --- a/wright/src/parser/lexer.rs +++ b/wright/src/parser/lexer.rs @@ -7,8 +7,8 @@ use super::fragment::Fragment; use std::iter::FusedIterator; use std::str::Chars; use std::{iter::Peekable, ptr}; -use unicode_ident::{is_xid_continue, is_xid_start}; use token::{Token, TokenTy}; +use unicode_ident::{is_xid_continue, is_xid_start}; pub mod token; pub mod trivial; @@ -97,15 +97,18 @@ impl<'src> Lexer<'src> { } } - /// Unsafe version of [Lexer::split_token]. - /// + /// Unsafe version of [Lexer::split_token]. + /// /// # Safety: /// - This function matches the safety guarantees of [Fragment::split_at_unchecked]. unsafe fn split_token_unchecked(&mut self, bytes: usize, kind: TokenTy) -> Token<'src> { let (token_fragment, new_remaining_fragment) = self.remaining.split_at_unchecked(bytes); self.remaining = new_remaining_fragment; - Token { variant: kind, fragment: token_fragment } + Token { + variant: kind, + fragment: token_fragment, + } } /// "Fork" this lexer, creating a new [`Lexer`] at the same position as this one that can be used for @@ -341,7 +344,7 @@ impl<'src> Lexer<'src> { token => return token, } - // Handle a trivial token if there is one. + // Handle a trivial token if there is one. if let Some(token) = trivial::try_consume_trivial_token(self) { return Some(token); } diff --git a/wright/src/parser/lexer/token.rs b/wright/src/parser/lexer/token.rs index e30b6851..f6a9f9e8 100644 --- a/wright/src/parser/lexer/token.rs +++ b/wright/src/parser/lexer/token.rs @@ -1,7 +1,7 @@ -//! Token models. +//! Token models. -use derive_more::Display; use crate::parser::fragment::Fragment; +use derive_more::Display; /// A token in wright source code. #[derive(Debug, Display)] diff --git a/wright/src/parser/lexer/trivial.rs b/wright/src/parser/lexer/trivial.rs index 7fb9284d..1e2f52a1 100644 --- a/wright/src/parser/lexer/trivial.rs +++ b/wright/src/parser/lexer/trivial.rs @@ -1,6 +1,9 @@ //! Trivial tokens and their implementation. -use super::{token::{Token, TokenTy}, Lexer}; +use super::{ + token::{Token, TokenTy}, + Lexer, +}; /// Trivial tokens that are two ASCII characters and can be matched directly /// against the input source code. @@ -57,17 +60,18 @@ pub const SINGLE_ASCII_CHAR_TRIVIAL_TOKENS: &[(u8, TokenTy)] = &[ (b'%', TokenTy::Mod), ]; - -/// Attempt to consume a "trivial" token from the start of the [Lexer]'s [Lexer::remaining] fragment. -/// -/// Leave the lexer unmodified if one is not available. +/// Attempt to consume a "trivial" token from the start of the [Lexer]'s [Lexer::remaining] fragment. +/// +/// Leave the lexer unmodified if one is not available. #[inline] pub fn try_consume_trivial_token<'src>(lexer: &mut Lexer<'src>) -> Option> { // Get the number of bytes remaining, since we need at least 1 to parse anything. let bytes_remaining: usize = lexer.bytes_remaining(); - // No token if there are no bytes of source left. - if bytes_remaining == 0 { return None; } + // No token if there are no bytes of source left. + if bytes_remaining == 0 { + return None; + } // Attempt to match any two-byte ASCII trivial tokens. // This must be done before single-ascii byte tokens since matching is greedy. @@ -79,25 +83,25 @@ pub fn try_consume_trivial_token<'src>(lexer: &mut Lexer<'src>) -> Option