Skip to content

Commit

Permalink
Add a source location for UnexpectedEndOfInput parse error (#504)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpschorr authored Oct 9, 2024
1 parent ee329ce commit 05793bd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Changed
- *BREAKING* partiql-parser: Added a source location to `ParseError::UnexpectedEndOfInput`

### Added

Expand Down
6 changes: 3 additions & 3 deletions partiql-parser/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ where

/// There were not enough tokens to complete a parse
#[error("Unexpected end of input")]
UnexpectedEndOfInput,
UnexpectedEndOfInput(Loc),

/// An otherwise un-categorized error occurred
#[error("Unknown parse error at `{}`", _0)]
Expand Down Expand Up @@ -83,14 +83,14 @@ where
Loc: Display,
{
/// Maps an `ParserError<Loc>` to `ParserError<Loc2>` by applying a function to each variant
pub fn map_loc<F, Loc2>(self, tx: F) -> ParseError<'input, Loc2>
pub fn map_loc<F, Loc2>(self, mut tx: F) -> ParseError<'input, Loc2>
where
Loc2: Display,
F: FnMut(Loc) -> Loc2,
{
match self {
ParseError::SyntaxError(l) => ParseError::SyntaxError(l.map_loc(tx)),
ParseError::UnexpectedEndOfInput => ParseError::UnexpectedEndOfInput,
ParseError::UnexpectedEndOfInput(l) => ParseError::UnexpectedEndOfInput((tx)(l)),
ParseError::UnexpectedToken(l) => ParseError::UnexpectedToken(l.map_loc(tx)),
ParseError::LexicalError(l) => ParseError::LexicalError(l.map_loc(tx)),
ParseError::IllegalState(s) => ParseError::IllegalState(s),
Expand Down
12 changes: 8 additions & 4 deletions partiql-parser/src/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ impl<'input> From<LalrpopError<'input>> for ParseError<'input, BytePosition> {
}

// TODO do something with UnrecognizedEof.expected
lalrpop_util::ParseError::UnrecognizedEof { expected: _, .. } => {
ParseError::UnexpectedEndOfInput
}
lalrpop_util::ParseError::UnrecognizedEof {
location,
expected: _,
} => ParseError::UnexpectedEndOfInput(location.into()),

lalrpop_util::ParseError::ExtraToken {
token: (start, token, end),
Expand Down Expand Up @@ -769,7 +770,10 @@ mod tests {
assert!(res.is_err());
let err_data = res.unwrap_err();
assert_eq!(1, err_data.errors.len());
assert_eq!(err_data.errors[0], ParseError::UnexpectedEndOfInput);
assert_eq!(
err_data.errors[0],
ParseError::UnexpectedEndOfInput(BytePosition::from(6))
);
}

#[test]
Expand Down

1 comment on commit 05793bd

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PartiQL (rust) Benchmark

Benchmark suite Current: 05793bd Previous: ee329ce Ratio
arith_agg-avg 758512 ns/iter (± 10612) 813580 ns/iter (± 2581) 0.93
arith_agg-avg_distinct 848621 ns/iter (± 7200) 874135 ns/iter (± 9462) 0.97
arith_agg-count 810473 ns/iter (± 80417) 834378 ns/iter (± 16561) 0.97
arith_agg-count_distinct 844508 ns/iter (± 2627) 868442 ns/iter (± 17108) 0.97
arith_agg-min 813068 ns/iter (± 4190) 839033 ns/iter (± 2413) 0.97
arith_agg-min_distinct 848537 ns/iter (± 2362) 877366 ns/iter (± 2075) 0.97
arith_agg-max 814747 ns/iter (± 6219) 843249 ns/iter (± 3262) 0.97
arith_agg-max_distinct 858958 ns/iter (± 3691) 884298 ns/iter (± 4461) 0.97
arith_agg-sum 809872 ns/iter (± 1987) 840443 ns/iter (± 2392) 0.96
arith_agg-sum_distinct 850432 ns/iter (± 2330) 874763 ns/iter (± 6113) 0.97
arith_agg-avg-count-min-max-sum 958506 ns/iter (± 4227) 989994 ns/iter (± 4709) 0.97
arith_agg-avg-count-min-max-sum-group_by 1220172 ns/iter (± 14437) 1269607 ns/iter (± 14409) 0.96
arith_agg-avg-count-min-max-sum-group_by-group_as 1831510 ns/iter (± 130173) 1866397 ns/iter (± 32696) 0.98
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct 1221445 ns/iter (± 19010) 1304722 ns/iter (± 17259) 0.94
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by 1510386 ns/iter (± 14587) 1579541 ns/iter (± 8088) 0.96
arith_agg-avg_distinct-count_distinct-min_distinct-max_distinct-sum_distinct-group_by-group_as 2106217 ns/iter (± 9047) 2174657 ns/iter (± 9232) 0.97
parse-1 6231 ns/iter (± 30) 6550 ns/iter (± 23) 0.95
parse-15 51206 ns/iter (± 356) 51925 ns/iter (± 142) 0.99
parse-30 99227 ns/iter (± 252) 100620 ns/iter (± 278) 0.99
compile-1 4231 ns/iter (± 16) 4303 ns/iter (± 69) 0.98
compile-15 31875 ns/iter (± 236) 32957 ns/iter (± 148) 0.97
compile-30 65414 ns/iter (± 1965) 68246 ns/iter (± 972) 0.96
plan-1 67815 ns/iter (± 298) 67789 ns/iter (± 258) 1.00
plan-15 1051828 ns/iter (± 9443) 1064079 ns/iter (± 14587) 0.99
plan-30 2110985 ns/iter (± 9730) 2133480 ns/iter (± 10208) 0.99
eval-1 12934632 ns/iter (± 204154) 13005971 ns/iter (± 128446) 0.99
eval-15 89239951 ns/iter (± 261802) 89519147 ns/iter (± 401778) 1.00
eval-30 171190106 ns/iter (± 440487) 172390848 ns/iter (± 2300370) 0.99
join 9933 ns/iter (± 1046) 9920 ns/iter (± 21) 1.00
simple 2559 ns/iter (± 25) 2618 ns/iter (± 6) 0.98
simple-no 454 ns/iter (± 5) 487 ns/iter (± 1) 0.93
numbers 48 ns/iter (± 0) 48 ns/iter (± 0) 1
parse-simple 936 ns/iter (± 2) 932 ns/iter (± 6) 1.00
parse-ion 2777 ns/iter (± 5) 2730 ns/iter (± 4) 1.02
parse-group 7987 ns/iter (± 26) 8067 ns/iter (± 17) 0.99
parse-complex 20795 ns/iter (± 42) 20886 ns/iter (± 51) 1.00
parse-complex-fexpr 28616 ns/iter (± 82) 28417 ns/iter (± 316) 1.01

This comment was automatically generated by workflow using github-action-benchmark.

Please sign in to comment.