Extract Erl float function
@@ -301,13 +301,7 @@ fn pattern(p: TypedPattern, env: &mut Env) -> Document {
Pattern::Int { value, .. } => value.to_doc(),
- Pattern::Float { value, .. } => {
- if value.ends_with(".") {
- format!("{}0", value).to_doc()
- } else {
- value.clone().to_doc()
- }
- }
+ Pattern::Float { value, .. } => float(value.as_ref()),
Pattern::String { value, .. } => string(value),
@@ -321,6 +315,14 @@ fn pattern(p: TypedPattern, env: &mut Env) -> Document {
}
}
+fn float(value: &str) -> Document {
+ if value.ends_with(".") {
+ format!("{}0", value).to_doc()
+ } else {
+ value.to_string().to_doc()
+ }
+}
+
fn pattern_list_cons(head: TypedPattern, tail: TypedPattern, env: &mut Env) -> Document {
list_cons(head, tail, env, pattern, |expr| match expr {
Pattern::Nil { .. } => ListType::Nil,
@@ -659,13 +661,7 @@ fn expr(expression: TypedExpr, env: &mut Env) -> Document {
TypedExpr::ListNil { .. } => "[]".to_doc(),
TypedExpr::Todo { .. } => "erlang:error({gleam_error, todo})".to_doc(),
TypedExpr::Int { value, .. } => value.to_doc(),
- TypedExpr::Float { value, .. } => {
- if value.ends_with(".") {
- format!("{}0", value).to_doc()
- } else {
- value.clone().to_doc()
- }
- }
+ TypedExpr::Float { value, .. } => float(value.as_ref()),
TypedExpr::String { value, .. } => string(value),
TypedExpr::Seq { first, then, .. } => seq(*first, *then, env),
TypedExpr::Pipe { left, right, .. } => pipe(*left, *right, env),
