Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,8 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = [ "env-filter" ] }

[build-dependencies]

[profile.release]
debug = "limited"
strip = true
lto = true
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright © 2002-2024 Athae Eredh Siniath and Others
Copyright © 2002-2025 Athae Eredh Siniath and Others

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
Expand Down
49 changes: 44 additions & 5 deletions src/error/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'i> TechniqueError<'i> {
.unwrap_or("?");

let line = i + 1;
let column = j;
let column = j + 1;

let width = line
.to_string()
Expand All @@ -38,7 +38,7 @@ impl<'i> TechniqueError<'i> {

{:width$} {}
{:width$} {} {}
{:width$} {} {:>j$}
{:width$} {} {:>column$}

{}
"#,
Expand Down Expand Up @@ -68,7 +68,7 @@ impl<'i> TechniqueError<'i> {
let j = calculate_column_number(self.source, self.offset);

let line = i + 1;
let column = j;
let column = j + 1;

format!(
"{}: {}:{}:{} {}",
Expand Down Expand Up @@ -103,8 +103,18 @@ fn calculate_line_number(content: &str, offset: usize) -> usize {
fn calculate_column_number(content: &str, offset: usize) -> usize {
let before = &content[..offset];
match before.rfind('\n') {
Some(start) => offset - start,
None => offset,
Some(start) => {
// Count Unicode characters from the start of the line to the offset
content[start + 1..offset]
.chars()
.count()
}
None => {
// No newline found, count characters from the beginning
before
.chars()
.count()
}
}
}

Expand Down Expand Up @@ -136,6 +146,35 @@ test
.unwrap();
assert_eq!(after, "test");
}

#[test]
fn counting_columns_ascii() {
let content = "This is a test";

let col = calculate_column_number(content, 5);
assert_eq!(col, 5); // After "This "
}

#[test]
fn counting_columns_unicode() {
// Test with Unicode characters like those in Three.t: "3.0 × 10⁸ m_s"
let content = "3.0 × 10⁸ m_s";

// At the underscore (× and ⁸ are multi-byte Unicode chars)
let offset = "3.0 × 10⁸ m".len();
let col = calculate_column_number(content, offset);
assert_eq!(col, 11); // Should count 11 characters, not bytes
}

#[test]
fn counting_columns_multiline() {
let content = "First line\nSecond × line";

// After "Second " on second line (× is multi-byte)
let offset = "First line\n".len();
let col = calculate_column_number(content, offset + 7);
assert_eq!(col, 7);
}
}

#[derive(Debug)]
Expand Down
2 changes: 1 addition & 1 deletion src/formatting/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -822,7 +822,7 @@ impl Formatter {
fn append_numeric(&mut self, numeric: &Numeric) {
match numeric {
Numeric::Integral(num) => self.append(Syntax::Numeric, &num.to_string()),
Numeric::Scientific(_) => todo!(),
Numeric::Scientific(quantity) => self.append(Syntax::Numeric, &quantity.to_string()),
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/language/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Types representing the Technique procedures language

mod quantity;
mod types;

// Re-export all public symbols
pub use quantity::*;
pub use types::*;
Loading