Skip to content

Commit

Permalink
chore: cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
vcfxb committed Jan 25, 2025
1 parent 6fbf2fc commit a434dde
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 36 deletions.
32 changes: 19 additions & 13 deletions wright/src/bin/wright.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ use anyhow::Result;
use clap::{Parser, Subcommand};
use std::path::PathBuf;
use wright::{
lexer::Lexer, source_tracking::{source::Source, SourceMap, SourceRef}
lexer::Lexer,
source_tracking::{source::Source, SourceMap, SourceRef},
};

/// The wright cli.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None, arg_required_else_help = true)]
struct Cli {
/// Whether the output should be only ASCII characters (default auto-detected, if `supports-unicode`
/// Whether the output should be only ASCII characters (default auto-detected, if `supports-unicode`
/// crate is compiled in).
///
/// This option does nothing if the `supports-unicode` crate was not enabled at compile time (in that case all
///
/// This option does nothing if the `supports-unicode` crate was not enabled at compile time (in that case all
/// output will be ASCII regardless).
#[arg(short = 'A', long = "ascii")]
force_ascii: bool,
Expand All @@ -34,9 +35,9 @@ enum Command {

/// Subcommand for showing information about this version of wright.
Show {
#[command(subcommand)]
command: ShowCommand
}
#[command(subcommand)]
command: ShowCommand,
},
}

/// Different sub-commands that the debug sub-command supports.
Expand All @@ -53,21 +54,22 @@ enum DebugCommand {
},
}

/// Different subcommands that can be used to get info about a copy of the wright CLI/compiler/etc.
/// Different subcommands that can be used to get info about a copy of the wright CLI/compiler/etc.
#[derive(Subcommand, Debug)]
enum ShowCommand {
/// Get the version string of this copy of the wright compiler.
Version,

/// Get the full list of feature names/strings that were enabled when this copy of wright was compiled.
Features
Features,
}

fn main() -> Result<()> {
// Parse the command line arguments.
let cli: Cli = Cli::parse();

#[cfg(feature = "supports-unicode")] {
#[cfg(feature = "supports-unicode")]
{
wright::util::supports_unicode::set_force_ascii(cli.force_ascii);
}

Expand All @@ -87,16 +89,20 @@ fn main() -> Result<()> {
}
}

Command::Show { command: ShowCommand::Version } => {
Command::Show {
command: ShowCommand::Version,
} => {
println!("wright {}", wright::build_info::PKG_VERSION);
}

Command::Show { command: ShowCommand::Features } => {
Command::Show {
command: ShowCommand::Features,
} => {
for feature in wright::build_info::FEATURES {
println!("{feature}");
}
}
}

Ok(())
}
2 changes: 1 addition & 1 deletion wright/src/lexer/token.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Token models.
use std::fmt::{self, Display};
use crate::source_tracking::fragment::Fragment;
use std::fmt::{self, Display};

/// A token in wright source code.
#[derive(Debug)]
Expand Down
2 changes: 0 additions & 2 deletions wright/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
// Compile without the standard library if the user chooses to do so.
#![cfg_attr(not(any(feature = "std", test)), no_std)]

// We want to enforce good stuff by default.
#![deny(missing_copy_implementations, missing_debug_implementations)]
#![deny(rustdoc::broken_intra_doc_links)]
#![warn(missing_docs)]

// Compiler directive to get docs.rs (which uses the nightly version of the rust compiler) to show
// info about feature required for various modules and functionality.
//
Expand Down
10 changes: 5 additions & 5 deletions wright/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ impl Parser {
self.peek().map(|token| &token.fragment)
}

/// Peek the [Fragment] of the next [Token] and clone it or return a clone of the
/// remainder [Fragment] of the internal [Lexer]
/// Peek the [Fragment] of the next [Token] and clone it or return a clone of the
/// remainder [Fragment] of the internal [Lexer]
/// (which will be empty, since there wasn't a [Token] to peek).
///
/// This is likely only useful for error reporting -- a clone of a potentially empty fragment is
///
/// This is likely only useful for error reporting -- a clone of a potentially empty fragment is
/// rarely ever useful otherwise.
pub fn peek_fragment_or_rest_cloned(&mut self) -> Fragment {
match self.peek() {
Expand All @@ -105,7 +105,7 @@ impl Parser {

// Assert that we're making the right assumptions about the remaining fragment.
// These are (unidiomatically) done using debug_assert -- perhaps that changes eventually
// however it should be fine for now, since this can only produce logic bugs (never memory or
// however it should be fine for now, since this can only produce logic bugs (never memory or
// concurrency bugs).
debug_assert!(rest.is_valid());
debug_assert!(rest.is_empty());
Expand Down
4 changes: 2 additions & 2 deletions wright/src/parser/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl ParserErrorKind {
ParserError {
kind: self,
location: f,
help: None
help: None,
}
}
}
Expand Down Expand Up @@ -79,7 +79,7 @@ impl ParserError {

// Put a little clarification if the parser reached end of source and then produced an error.
let message = if self.location.is_empty_at_end_of_source() {
Cow::Borrowed("found end of source here")
Cow::Borrowed("found end of source here")
} else {
Cow::Borrowed("")
};
Expand Down
9 changes: 4 additions & 5 deletions wright/src/parser/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@ use super::{
error::{ParserError, ParserErrorKind},
Parser,
};
use crate::{
ast::identifier::Identifier,
lexer::token::TokenTy,
};
use crate::{ast::identifier::Identifier, lexer::token::TokenTy};

impl Identifier {
/// Parse an [Identifier] from a [Parser]. Leave the [Parser] unadvanced otherwise.
pub fn parse(parser: &mut Parser) -> Result<Self, ParserError> {
parser
.next_if_is(TokenTy::Identifier)
.map(|token| Identifier { fragment: token.fragment })
.map(|token| Identifier {
fragment: token.fragment,
})
.ok_or_else(|| {
ParserErrorKind::ExpectedIdentifier.at(parser.peek_fragment_or_rest_cloned())
})
Expand Down
1 change: 0 additions & 1 deletion wright/src/parser/literal.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
//! Literal parser implementations.
mod integer;

2 changes: 1 addition & 1 deletion wright/src/parser/literal/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
use num::{BigUint, Num};

use crate::parser::error::{ParserError, ParserErrorKind};
use crate::parser::Parser;
use crate::{ast::literal::IntegerLiteral, lexer::token::TokenTy};
use crate::parser::error::{ParserError, ParserErrorKind};

impl IntegerLiteral {
/// Parse an integer literal from the given [Parser].
Expand Down
4 changes: 2 additions & 2 deletions wright/src/source_tracking/fragment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl Fragment {
}

/// Check if this fragment is empty at the end of it's source.
///
///
/// Uses [debug_assert] to check for validity.
pub fn is_empty_at_end_of_source(&self) -> bool {
debug_assert!(self.is_valid());
Expand Down Expand Up @@ -158,7 +158,7 @@ impl Fragment {
/// This is the same as [Fragment::split_at] except it does not check that the created fragments are valid or
/// that either can call [Fragment::as_str] without panicking.
/// Use with caution.
///
///
/// Note that this is not technically `unsafe`, since all bugs that may emerge from abuse/misuse here are logic
/// bugs (not memory or concurrency bugs).
pub fn split_at_unchecked(&self, bytes_from_start: usize) -> (Self, Self) {
Expand Down
9 changes: 5 additions & 4 deletions wright/src/util/supports_unicode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ pub fn set_force_ascii(force_ascii: bool) {

/// Should we be writing unicode out to the user's terminal?
pub fn supports_unicode() -> bool {
#[cfg(feature = "supports-unicode")] {
#[cfg(feature = "supports-unicode")]
{
use core::sync::atomic::Ordering;

!FORCE_ASCII.load(Ordering::Acquire) &&
supports_unicode_crate::supports_unicode()
!FORCE_ASCII.load(Ordering::Acquire) && supports_unicode_crate::supports_unicode()
}

#[cfg(not(feature = "supports-unicode"))] {
#[cfg(not(feature = "supports-unicode"))]
{
false
}
}

0 comments on commit a434dde

Please sign in to comment.