Skip to content

Commit

Permalink
Use shorthand label syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Dec 7, 2024
1 parent faa568b commit c7546ae
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 68 deletions.
2 changes: 1 addition & 1 deletion src/lenient_parse.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ pub fn to_int_with_base(

text
|> tokenizer.tokenize_int
|> parser.parse_int_tokens(base: base)
|> parser.parse_int_tokens(base:)
}
4 changes: 2 additions & 2 deletions src/lenient_parse/internal/build.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ pub fn float_value(

let decimal =
pilkku.new_bigint(
sign: sign,
coefficient: coefficient,
sign:,
coefficient:,
exponent: bigi.from_int(-exponent),
)

Expand Down
2 changes: 1 addition & 1 deletion src/lenient_parse/internal/convert.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import gleam/list
import lenient_parse/internal/base_constants.{base_10}

pub fn digits_to_int(digits digits: Deque(Int)) -> Int {
digits_to_int_with_base(digits: digits, base: base_10)
digits_to_int_with_base(digits:, base: base_10)
}

pub fn digits_to_int_with_base(digits digits: Deque(Int), base base: Int) -> Int {
Expand Down
68 changes: 25 additions & 43 deletions src/lenient_parse/internal/parser.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ pub fn parse_float_tokens(
Some(_), True -> Error(WhitespaceOnlyString)
_, _ ->
Ok(build.float_value(
is_positive: is_positive,
whole_digits: whole_digits,
fractional_digits: fractional_digits,
is_positive:,
whole_digits:,
fractional_digits:,
scale_factor: exponent,
))
}
Expand Down Expand Up @@ -173,7 +173,7 @@ pub fn parse_int_tokens(
Error(BasePrefixOnly(index_range, prefix))
Some(_), _, True -> Error(WhitespaceOnlyString)
_, _, _ -> {
let value = digits |> digits_to_int_with_base(base: base)
let value = digits |> digits_to_int_with_base(base:)
let value = case is_positive {
True -> value
False -> -value
Expand All @@ -187,7 +187,7 @@ fn parse_whitespace(
tokens tokens: List(Token),
index index: Int,
) -> Result(ParseData(Option(String)), ParseError) {
do_parse_whitespace(tokens: tokens, index: index, acc: "")
do_parse_whitespace(tokens:, index:, acc: "")
}

fn do_parse_whitespace(
Expand All @@ -210,7 +210,7 @@ fn do_parse_whitespace(
_ -> Some(acc)
}

Ok(ParseData(data: data, next_index: index, tokens: tokens))
Ok(ParseData(data:, next_index: index, tokens:))
}
}
}
Expand All @@ -224,7 +224,7 @@ fn parse_sign(
[Sign(index, _, is_positive), ..rest] ->
Ok(ParseData(data: is_positive, next_index: index + 1, tokens: rest))
_ -> {
Ok(ParseData(data: True, next_index: index, tokens: tokens))
Ok(ParseData(data: True, next_index: index, tokens:))
}
}
}
Expand All @@ -243,40 +243,22 @@ fn parse_base_prefix(
Ok(Digit(_, specifier, _))
if { base == base_0 || base == base_2 }
&& { specifier == "b" || specifier == "B" }
->
Ok(base_prefix_data(
tokens: rest,
index: index,
specifier: specifier,
base: base_2,
))
-> Ok(base_prefix_data(tokens: rest, index:, specifier:, base: base_2))
Ok(Digit(_, specifier, _))
if { base == base_0 || base == base_8 }
&& { specifier == "o" || specifier == "O" }
->
Ok(base_prefix_data(
tokens: rest,
index: index,
specifier: specifier,
base: base_8,
))
-> Ok(base_prefix_data(tokens: rest, index:, specifier:, base: base_8))
Ok(Digit(_, specifier, _))
if { base == base_0 || base == base_16 }
&& { specifier == "x" || specifier == "X" }
->
Ok(base_prefix_data(
tokens: rest,
index: index,
specifier: specifier,
base: base_16,
))
-> Ok(base_prefix_data(tokens: rest, index:, specifier:, base: base_16))
Ok(Digit(index, character, _)) if base == base_0 -> {
Error(UnknownCharacter(index, character))
}
_ -> Ok(ParseData(data: None, next_index: index, tokens: tokens))
_ -> Ok(ParseData(data: None, next_index: index, tokens:))
}
}
_ -> Ok(ParseData(data: None, next_index: index, tokens: tokens))
_ -> Ok(ParseData(data: None, next_index: index, tokens:))
}
}

Expand All @@ -301,7 +283,7 @@ fn parse_decimal_point(
[Unknown(index, character), ..] -> Error(UnknownCharacter(index, character))
[DecimalPoint(index), ..rest] ->
Ok(ParseData(data: True, next_index: index + 1, tokens: rest))
_ -> Ok(ParseData(data: False, next_index: index, tokens: tokens))
_ -> Ok(ParseData(data: False, next_index: index, tokens:))
}
}

Expand All @@ -317,7 +299,7 @@ fn parse_exponent_symbol(
next_index: index + 1,
tokens: rest,
))
_ -> Ok(ParseData(data: None, next_index: index, tokens: tokens))
_ -> Ok(ParseData(data: None, next_index: index, tokens:))
}
}

Expand All @@ -328,12 +310,12 @@ fn parse_digits(
has_base_prefix has_base_prefix: Bool,
) -> Result(ParseData(Deque(Int)), ParseError) {
do_parse_digits(
tokens: tokens,
index: index,
base: base,
tokens:,
index:,
base:,
acc: deque.new(),
at_beginning: True,
has_base_prefix: has_base_prefix,
has_base_prefix:,
)
}

Expand Down Expand Up @@ -373,10 +355,10 @@ fn do_parse_digits(
do_parse_digits(
tokens: rest,
index: index + 1,
base: base,
acc: acc,
base:,
acc:,
at_beginning: False,
has_base_prefix: has_base_prefix,
has_base_prefix:,
)
}
[Digit(index, character, _), ..] if base == base_0 -> {
Expand All @@ -385,15 +367,15 @@ fn do_parse_digits(
[Digit(index, _, value), ..rest] if value < base -> {
do_parse_digits(
tokens: rest,
index: index,
base: base,
index:,
base:,
acc: acc |> deque.push_back(value),
at_beginning: False,
has_base_prefix: has_base_prefix,
has_base_prefix:,
)
}
[Digit(index, character, value), ..] ->
Error(OutOfBaseRange(index, character, value, base))
_ -> Ok(ParseData(data: acc, next_index: index, tokens: tokens))
_ -> Ok(ParseData(data: acc, next_index: index, tokens:))
}
}
7 changes: 1 addition & 6 deletions src/lenient_parse/internal/pilkku/pilkku.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,7 @@ pub fn new_bigint(
_ -> bigi.from_int(1)
}

Decimal(
sign: sign,
coefficient: coefficient,
exponent: exponent,
flags: set.new(),
)
Decimal(sign:, coefficient:, exponent:, flags: set.new())
}

/// Cast the decimal into a float.
Expand Down
4 changes: 2 additions & 2 deletions src/lenient_parse/internal/scale.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ pub fn deques(

pub fn float(factor: Float, exponent: Int) -> Float {
do_float(
factor: factor,
exponent: exponent,
factor:,
exponent:,
scale_factor: 1,
exponent_is_positive: exponent >= 0,
)
Expand Down
12 changes: 6 additions & 6 deletions src/lenient_parse/internal/tokenizer.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ fn do_tokenize_float(
_ ->
common_token(
character: first,
index: index,
whitespace_character_dict: whitespace_character_dict,
index:,
whitespace_character_dict:,
tokenize_character_as_digit: fn(digit_value) {
digit_value < base_10
},
Expand All @@ -47,7 +47,7 @@ fn do_tokenize_float(
do_tokenize_float(
characters: rest,
index: index + 1,
whitespace_character_dict: whitespace_character_dict,
whitespace_character_dict:,
acc: [token, ..acc],
)
}
Expand Down Expand Up @@ -79,15 +79,15 @@ fn do_tokenize_int(
let token =
common_token(
character: first,
index: index,
index:,
tokenize_character_as_digit: fn(_) { True },
whitespace_character_dict: whitespace_character_dict,
whitespace_character_dict:,
)

do_tokenize_int(
characters: rest,
index: index + 1,
whitespace_character_dict: whitespace_character_dict,
whitespace_character_dict:,
acc: [token, ..acc],
)
}
Expand Down
4 changes: 2 additions & 2 deletions test/data/float/invalid_float_data.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ fn float_test_data(
let printable_text = input |> helpers.to_printable_text

FloatTestData(
input: input,
expected_program_output: expected_program_output,
input:,
expected_program_output:,
expected_python_output: Error(python_error_function(printable_text)),
)
}
Expand Down
6 changes: 3 additions & 3 deletions test/data/integer/invalid_integer_data.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ fn integer_test_data(
let printable_text = input |> helpers.to_printable_text

IntegerTestData(
input: input,
base: base,
expected_program_output: expected_program_output,
input:,
base:,
expected_program_output:,
expected_python_output: Error(python_error_function(printable_text, base)),
)
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn do_to_printable_text(

do_to_printable_text(
characters: rest,
whitespace_character_dict: whitespace_character_dict,
whitespace_character_dict:,
acc: acc <> printable,
)
}
Expand Down
2 changes: 1 addition & 1 deletion test/to_int_parse_test.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn to_int_tests() {
use <- it(message)

input
|> lenient_parse.to_int_with_base(base: base)
|> lenient_parse.to_int_with_base(base:)
|> expect.to_equal(expected_program_output)
}),
)
Expand Down

0 comments on commit c7546ae

Please sign in to comment.