From 046a3e5b206cb113887a28918c02aad1709e3aa7 Mon Sep 17 00:00:00 2001 From: electria Date: Fri, 9 Oct 2026 16:07:05 -0700 Subject: [PATCH] feat: ignore underscores in input this isn't useful for typst usually, since underscores are subscript and don't appear in expressions much. however, when using tylc as a standalone calculator, this is useful eg to seperate sets of three digits. idea totally stolen from rust literals note that this might cause problems when it comes to special variables, eg A_n for Avogadro's number (but just A is fine) --- src/formatting.rs | 24 +++++++++++++----------- src/main.rs | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index eb097c0..dad87e5 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -2,7 +2,9 @@ use rug::Float; use crate::nodes::{self, Error}; -pub fn pretty_eval(mut input: String, max_digits: usize) -> Result { +pub fn pretty_eval(input: &str, max_digits: usize) -> Result { + let mut input = input.replace('_', ""); + // no need to remove the characters here, // as we ignore the them in all other logic already let should_add_back_alignment = input.contains('&'); @@ -49,20 +51,20 @@ pub fn pretty_eval(mut input: String, max_digits: usize) -> Result usize { diff --git a/src/main.rs b/src/main.rs index c3349d2..c9634da 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,7 +17,7 @@ fn main() -> ExitCode { buf }); - match lib::formatting::pretty_eval(input, 10) { + match lib::formatting::pretty_eval(&input, 10) { Ok(s) => println!("{s}"), Err(e) => {