mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 23:31:12 +00:00
[WIP] Update can & pattern to store numbers as validated strs
This commit is contained in:
parent
6741d93517
commit
adabf70132
4 changed files with 164 additions and 59 deletions
|
@ -1,6 +1,6 @@
|
|||
use crate::env::Env;
|
||||
use crate::expr::{canonicalize_expr, unescape_char, Expr, Output};
|
||||
use crate::num::{finish_parsing_base, finish_parsing_float, finish_parsing_int};
|
||||
use crate::num::{finish_parsing_base, finish_parsing_int, validate_float_str};
|
||||
use crate::scope::Scope;
|
||||
use roc_module::ident::{Ident, Lowercase, TagName};
|
||||
use roc_module::symbol::Symbol;
|
||||
|
@ -25,9 +25,9 @@ pub enum Pattern {
|
|||
ext_var: Variable,
|
||||
destructs: Vec<Located<RecordDestruct>>,
|
||||
},
|
||||
IntLiteral(Variable, i64),
|
||||
NumLiteral(Variable, i64),
|
||||
FloatLiteral(Variable, f64),
|
||||
IntLiteral(Variable, Box<str>),
|
||||
NumLiteral(Variable, Box<str>),
|
||||
FloatLiteral(Variable, Box<str>),
|
||||
StrLiteral(Box<str>),
|
||||
Underscore,
|
||||
|
||||
|
@ -185,13 +185,13 @@ pub fn canonicalize_pattern<'a>(
|
|||
}
|
||||
}
|
||||
|
||||
FloatLiteral(string) => match pattern_type {
|
||||
WhenBranch => match finish_parsing_float(string) {
|
||||
FloatLiteral(str) => match pattern_type {
|
||||
WhenBranch => match validate_float_str(str) {
|
||||
Err(_error) => {
|
||||
let problem = MalformedPatternProblem::MalformedFloat;
|
||||
malformed_pattern(env, problem, region)
|
||||
}
|
||||
Ok(float) => Pattern::FloatLiteral(var_store.fresh(), float),
|
||||
Ok(_float) => Pattern::FloatLiteral(var_store.fresh(), (*str).into()),
|
||||
},
|
||||
ptype => unsupported_pattern(env, ptype, region),
|
||||
},
|
||||
|
@ -201,13 +201,13 @@ pub fn canonicalize_pattern<'a>(
|
|||
TopLevelDef | DefExpr => bad_underscore(env, region),
|
||||
},
|
||||
|
||||
NumLiteral(string) => match pattern_type {
|
||||
WhenBranch => match finish_parsing_int(string) {
|
||||
NumLiteral(str) => match pattern_type {
|
||||
WhenBranch => match finish_parsing_int(str) {
|
||||
Err(_error) => {
|
||||
let problem = MalformedPatternProblem::MalformedInt;
|
||||
malformed_pattern(env, problem, region)
|
||||
}
|
||||
Ok(int) => Pattern::NumLiteral(var_store.fresh(), int),
|
||||
Ok(_int) => Pattern::NumLiteral(var_store.fresh(), (*str).into()),
|
||||
},
|
||||
ptype => unsupported_pattern(env, ptype, region),
|
||||
},
|
||||
|
@ -223,11 +223,9 @@ pub fn canonicalize_pattern<'a>(
|
|||
malformed_pattern(env, problem, region)
|
||||
}
|
||||
Ok(int) => {
|
||||
if *is_negative {
|
||||
Pattern::IntLiteral(var_store.fresh(), -int)
|
||||
} else {
|
||||
Pattern::IntLiteral(var_store.fresh(), int)
|
||||
}
|
||||
let sign_str = if *is_negative { "-" } else { "" };
|
||||
let int_str = format!("{}{}", sign_str, int.to_string()).into_boxed_str();
|
||||
Pattern::IntLiteral(var_store.fresh(), int_str)
|
||||
}
|
||||
},
|
||||
ptype => unsupported_pattern(env, ptype, region),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue