diff --git a/core/src/ident.rs b/core/src/ident.rs index 95eab276..0c9fc9a2 100644 --- a/core/src/ident.rs +++ b/core/src/ident.rs @@ -24,7 +24,7 @@ impl Ident { pub(crate) fn is_prefix_unit(&self) -> bool { // when changing this also make sure to change number output formatting // lexer identifier splitting - self.0 == "$" || self.0 == "\u{a3}" + ["$", "\u{a3}", "\u{a5}"].contains(&&*self.0) } pub(crate) fn serialize(&self, write: &mut impl io::Write) -> FResult<()> { diff --git a/core/src/lexer.rs b/core/src/lexer.rs index b2cef15e..88722cb8 100644 --- a/core/src/lexer.rs +++ b/core/src/lexer.rs @@ -436,7 +436,7 @@ fn is_valid_in_ident(ch: char, prev: Option) -> bool { '㏌', '㏏', '㏐', '㏓', '㏔', '㏕', '㏖', '㏗', '㏙', '㏛', '㏜', '㏝', ]; let only_valid_by_themselves = ['%', '‰', '‱', '′', '″', '’', '”', 'π']; - let split_on_subsequent_digit = ['$', '£']; + let split_on_subsequent_digit = ['$', '£', '¥']; let always_invalid = ['λ']; if always_invalid.contains(&ch) { false diff --git a/core/src/lib.rs b/core/src/lib.rs index a1fb2d42..649ac058 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -607,6 +607,7 @@ pub mod test_utils { "HKD" => 8.0, "AUD" => 1.3, "PLN" => 0.2, + "JPY" => 149.9, _ => panic!("unknown currency {currency}"), }) } diff --git a/core/src/num/unit.rs b/core/src/num/unit.rs index 5785886b..a9306506 100644 --- a/core/src/num/unit.rs +++ b/core/src/num/unit.rs @@ -948,7 +948,7 @@ impl FormattedValue { kind: SpanKind::Ident, }); } - if self.unit_str == "$" || self.unit_str == "\u{a3}" && !attrs.plain_number { + if ["$", "\u{a3}", "\u{a5}"].contains(&self.unit_str.as_str()) && !attrs.plain_number { spans.push(Span { string: self.unit_str, kind: SpanKind::Ident, diff --git a/core/src/parser.rs b/core/src/parser.rs index b552b5dc..87af346c 100644 --- a/core/src/parser.rs +++ b/core/src/parser.rs @@ -200,7 +200,7 @@ fn parse_apply_cont<'a>(input: &'a [Token], lhs: &Expr) -> ParseResult<'a> { } Expr::Apply(Box::new(lhs.clone()), Box::new(rhs)) } - // support e.g. '$5' or '£3' + // support e.g. '$5', '£3' or '¥10' (Expr::Ident(i), Expr::Literal(Value::Num(_))) if i.is_prefix_unit() => { Expr::Apply(Box::new(lhs.clone()), Box::new(rhs)) } diff --git a/core/src/units/builtin.rs b/core/src/units/builtin.rs index 3715764c..dd07a84f 100644 --- a/core/src/units/builtin.rs +++ b/core/src/units/builtin.rs @@ -688,7 +688,8 @@ const CURRENCIES: &[UnitTuple] = &[ ("$", "$", "USD", ""), ("euro", "euros", "EUR", ""), ("\u{20ac}", "\u{20ac}", "EUR", ""), // Euro symbol - ("\u{a3}", "\u{a3}", "GBP", ""), + ("\u{a3}", "\u{a3}", "GBP", ""), // £ + ("\u{a5}", "\u{a5}", "JPY", ""), // ¥ ("AU$", "AU$", "AUD", ""), ("HK$", "HK$", "HKD", ""), ("NZ$", "NZ$", "NZD", ""), diff --git a/core/tests/integration_tests.rs b/core/tests/integration_tests.rs index 83f8ee8a..3f8b3bf4 100644 --- a/core/tests/integration_tests.rs +++ b/core/tests/integration_tests.rs @@ -5397,6 +5397,11 @@ fn gbp_symbol() { test_eval("£5 + £3", "£8"); } +#[test] +fn jpy_symbol() { + test_eval("¥5 + ¥3", "¥8"); +} + #[test] fn two_statements() { test_eval("2; 4", "4");