diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 17:16:41 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2024-05-01 17:16:41 +0200 |
commit | b6ced080ed6365aecff766c2cd5da7f219c8f977 (patch) | |
tree | ae23939c1cf5599dbff852a3b2e82a062f71d584 /crates/rebel-parse | |
parent | fbe4a0a4f76d0bc8beef3972bd19ca1ac2fc1feb (diff) | |
download | rebel-b6ced080ed6365aecff766c2cd5da7f219c8f977.tar rebel-b6ced080ed6365aecff766c2cd5da7f219c8f977.zip |
rebel-parse: store number literals as i64 instead of u64
Avoid a useless conversion during eval.
Diffstat (limited to 'crates/rebel-parse')
-rw-r--r-- | crates/rebel-parse/src/ast/expr.rs | 2 | ||||
-rw-r--r-- | crates/rebel-parse/src/grammar/recipe.rs | 4 |
2 files changed, 3 insertions, 3 deletions
diff --git a/crates/rebel-parse/src/ast/expr.rs b/crates/rebel-parse/src/ast/expr.rs index 429dfa2..9ac4a38 100644 --- a/crates/rebel-parse/src/ast/expr.rs +++ b/crates/rebel-parse/src/ast/expr.rs @@ -163,7 +163,7 @@ impl<'a> From<&DestrPat<'a>> for Expr<'a> { pub enum Literal<'a> { Unit, Bool(bool), - Int(u64), + Int(i64), Str { pieces: Vec<StrPiece<'a>>, kind: StrKind, diff --git a/crates/rebel-parse/src/grammar/recipe.rs b/crates/rebel-parse/src/grammar/recipe.rs index 2aa665a..2d342ad 100644 --- a/crates/rebel-parse/src/grammar/recipe.rs +++ b/crates/rebel-parse/src/grammar/recipe.rs @@ -197,7 +197,7 @@ peg::parser! { ast::Ident { name: content } } - rule number() -> u64 + rule number() -> i64 = [Token::Number(s)] { ? let (radix, rest) = if let Some(rest) = s.strip_prefix("0x") { (16, rest) @@ -209,7 +209,7 @@ peg::parser! { (10, *s) }; let digits = rest.replace('_', ""); - u64::from_str_radix(&digits, radix).or(Err("number")) + i64::from_str_radix(&digits, radix).or(Err("number")) } rule p_(ch: char) |