Skip to content

Commit

Permalink
Rename InvalidCharacter to UnknownCharacter
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephTLyons committed Nov 4, 2024
1 parent 5cb2539 commit 33ada9d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 20 deletions.
18 changes: 9 additions & 9 deletions src/lenient_parse/internal/parse.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import lenient_parse/internal/tokenizer.{
type Token, DecimalPoint, Digit, Sign, Underscore, Unknown, Whitespace,
}
import parse_error.{
type ParseError, EmptyString, InvalidCharacter, InvalidDecimalPosition,
InvalidDigitPosition, InvalidSignPosition, InvalidUnderscorePosition,
type ParseError, EmptyString, InvalidDecimalPosition, InvalidDigitPosition,
InvalidSignPosition, InvalidUnderscorePosition, UnknownCharacter,
WhitespaceOnlyString,
}

Expand Down Expand Up @@ -99,7 +99,7 @@ fn parse_whitespace(
}
[first, ..rest] -> {
case first {
Unknown(character) -> Error(InvalidCharacter(character, index))
Unknown(character) -> Error(UnknownCharacter(character, index))
Whitespace(whitespace) ->
parse_whitespace(rest, acc <> whitespace, index + 1)
_ -> {
Expand All @@ -121,7 +121,7 @@ fn parse_sign(
[] -> Ok(#("+", tokens, index))
[first, ..rest] -> {
case first {
Unknown(character) -> Error(InvalidCharacter(character, index))
Unknown(character) -> Error(UnknownCharacter(character, index))
Sign(a) -> Ok(#(a, rest, index + 1))
_ -> Ok(#("+", tokens, index))
}
Expand All @@ -137,7 +137,7 @@ fn parse_decimal_point(
[] -> Ok(#(False, tokens, index))
[first, ..rest] -> {
case first {
Unknown(character) -> Error(InvalidCharacter(character, index))
Unknown(character) -> Error(UnknownCharacter(character, index))
DecimalPoint -> Ok(#(True, rest, index + 1))
_ -> Ok(#(False, rest, index))
}
Expand Down Expand Up @@ -179,8 +179,8 @@ fn parse_digit(
Error(parse_error.InvalidUnderscorePosition(index))
Underscore -> parse_digit(rest, acc, index + 1, beginning_index)
Whitespace(whitespace) if at_beginning ->
Error(InvalidCharacter(whitespace, index))
Unknown(character) -> Error(InvalidCharacter(character, index))
Error(UnknownCharacter(whitespace, index))
Unknown(character) -> Error(UnknownCharacter(character, index))
_ -> {
case acc {
"" -> Ok(#(None, tokens, index))
Expand All @@ -197,8 +197,8 @@ fn extraneous_token_error(token: Token, index) -> ParseError {
Digit(digit) -> InvalidDigitPosition(digit, index)
Sign(sign) -> InvalidSignPosition(sign, index)
Underscore -> InvalidUnderscorePosition(index)
Unknown(character) -> InvalidCharacter(character, index)
Whitespace(whitespace) -> InvalidCharacter(whitespace, index)
Unknown(character) -> UnknownCharacter(character, index)
Whitespace(whitespace) -> UnknownCharacter(whitespace, index)
DecimalPoint -> InvalidDecimalPosition(index)
}
}
6 changes: 3 additions & 3 deletions src/parse_error.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub type ParseError {
///
/// - `character`: The invalid character as a `String`.
/// - `index`: The position of the invalid character in the input string.
InvalidCharacter(character: String, index: Int)
UnknownCharacter(character: String, index: Int)

/// Represents an error when Gleam's `float.parse` fails after custom parsing
/// and coercion.
Expand All @@ -60,8 +60,8 @@ pub type ParseError {
pub fn to_string(error: ParseError) -> String {
case error {
GleamIntParseError -> "gleam integer parse error"
InvalidCharacter(character, index) ->
"invalid character \""
UnknownCharacter(character, index) ->
"unknown character \""
<> character
<> "\" at index: "
<> index |> int.to_string
Expand Down
16 changes: 8 additions & 8 deletions test/shared_test_data.gleam
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import parse_error.{
type ParseError, EmptyString, InvalidCharacter, InvalidDecimalPosition,
InvalidDigitPosition, InvalidSignPosition, InvalidUnderscorePosition,
type ParseError, EmptyString, InvalidDecimalPosition, InvalidDigitPosition,
InvalidSignPosition, InvalidUnderscorePosition, UnknownCharacter,
WhitespaceOnlyString,
}

Expand Down Expand Up @@ -172,12 +172,12 @@ pub const float_data = [
),
FloatTestData(
input: "abc",
output: Error(InvalidCharacter("a", 0)),
output: Error(UnknownCharacter("a", 0)),
python_output: Error(Nil),
),
FloatTestData(
input: "100.00c01",
output: Error(InvalidCharacter("c", 6)),
output: Error(UnknownCharacter("c", 6)),
python_output: Error(Nil),
),
]
Expand Down Expand Up @@ -283,17 +283,17 @@ pub const int_data = [
),
IntegerTestData(
input: "a",
output: Error(InvalidCharacter("a", 0)),
output: Error(UnknownCharacter("a", 0)),
python_output: Error(Nil),
),
IntegerTestData(
input: "1b1",
output: Error(InvalidCharacter("b", 1)),
output: Error(UnknownCharacter("b", 1)),
python_output: Error(Nil),
),
IntegerTestData(
input: "+ 1",
output: Error(InvalidCharacter(" ", 1)),
output: Error(UnknownCharacter(" ", 1)),
python_output: Error(Nil),
),
IntegerTestData(
Expand All @@ -308,7 +308,7 @@ pub const int_data = [
),
IntegerTestData(
input: "abc",
output: Error(InvalidCharacter("a", 0)),
output: Error(UnknownCharacter("a", 0)),
python_output: Error(Nil),
),
IntegerTestData(
Expand Down

0 comments on commit 33ada9d

Please sign in to comment.