Skip to content

Commit

Permalink
Add a private new() function for ParseState
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Oct 20, 2024
1 parent 28b3f10 commit c4a87b2
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/lenient_parse/internal/coerce.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,29 @@ pub type ParseState {
)
}

pub fn coerce_into_float_string(text: String) -> Result(String, ParseError) {
fn new(text: String, allow_float: Bool) -> ParseState {
State(
tokens: text |> tokenizer.tokenize_number_string,
index: 0,
previous: None,
text_length: text |> string.length,
tracker: whitespace_block_tracker.new(),
allow_float: True,
allow_float: allow_float,
seen_decimal: False,
seen_digit: False,
acc: "",
)
}

pub fn coerce_into_float_string(text: String) -> Result(String, ParseError) {
text
|> new(True)
|> coerce_into_valid_number_string
}

pub fn coerce_into_int_string(text: String) -> Result(String, ParseError) {
State(
tokens: text |> tokenizer.tokenize_number_string,
index: 0,
previous: None,
text_length: text |> string.length,
tracker: whitespace_block_tracker.new(),
allow_float: False,
seen_decimal: False,
seen_digit: False,
acc: "",
)
text
|> new(False)
|> coerce_into_valid_number_string
}

Expand Down

0 comments on commit c4a87b2

Please sign in to comment.