diff --git a/README.md b/README.md index 363e55a..566cf17 100644 --- a/README.md +++ b/README.md @@ -432,7 +432,7 @@ Values are denoted as displayed in the following table. |------------|---------| | `Value::String` | `"abc"`, `""`, `"a\"b\\c"` | | `Value::Boolean` | `true`, `false` | -| `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0x1e` | +| `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0X1e`, `$fe` | | `Value::Float` | `3.`, `.35`, `1.00`, `0.5`, `123.554`, `23e4`, `-2e-3`, `3.54e+2` | | `Value::Tuple` | `(3, 55.0, false, ())`, `(1, 2)` | | `Value::Empty` | `()` | diff --git a/src/lib.rs b/src/lib.rs index 763e94b..e80f395 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -413,7 +413,7 @@ //! |------------|---------| //! | `Value::String` | `"abc"`, `""`, `"a\"b\\c"` | //! | `Value::Boolean` | `true`, `false` | -//! | `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0x1e` | +//! | `Value::Int` | `3`, `-9`, `0`, `135412`, `0xfe02`, `-0X1e`, `$fe` | //! | `Value::Float` | `3.`, `.35`, `1.00`, `0.5`, `123.554`, `23e4`, `-2e-3`, `3.54e+2` | //! | `Value::Tuple` | `(3, 55.0, false, ())`, `(1, 2)` | //! | `Value::Empty` | `()` | diff --git a/src/token/mod.rs b/src/token/mod.rs index ea22890..92e7521 100644 --- a/src/token/mod.rs +++ b/src/token/mod.rs @@ -480,7 +480,11 @@ pub(crate) fn tokenize(string: &str) -> EvalexprResult> { } fn parse_dec_or_hex(literal: &str) -> Result { - if let Some(literal) = literal.strip_prefix("0x") { + if let Some(literal) = literal.strip_prefix("0x").or_else(|| { + literal + .strip_prefix("0X") + .or_else(|| literal.strip_prefix('$')) + }) { IntType::from_str_radix(literal, 16) } else { IntType::from_str_radix(literal, 10) diff --git a/tests/integration.rs b/tests/integration.rs index 695056b..5cd34a7 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -2316,6 +2316,9 @@ fn test_hex() { assert_eq!(eval("0x3"), Ok(Value::Int(3))); assert_eq!(eval("0xFF"), Ok(Value::Int(255))); assert_eq!(eval("-0xFF"), Ok(Value::Int(-255))); + assert_eq!(eval("0XFF"), Ok(Value::Int(255))); + assert_eq!(eval("$fe"), Ok(Value::Int(254))); + assert!(eval("$xy").is_err()); assert_eq!( eval("0x"), // The "VariableIdentifierNotFound" error is what evalexpr currently returns,