(tokens: &[Token], position: &usize)
| 3753 | } |
| 3754 | |
| 3755 | fn un_expected_expression_error(tokens: &[Token], position: &usize) -> Box<Diagnostic> { |
| 3756 | let location = calculate_safe_location(tokens, *position); |
| 3757 | |
| 3758 | if *position == 0 || *position >= tokens.len() { |
| 3759 | return Diagnostic::error("Can't complete parsing this expression") |
| 3760 | .with_location(location) |
| 3761 | .as_boxed(); |
| 3762 | } |
| 3763 | |
| 3764 | let current = &tokens[*position]; |
| 3765 | let previous = &tokens[*position - 1]; |
| 3766 | |
| 3767 | // Make sure `ASC` and `DESC` are used in ORDER BY statement |
| 3768 | if current.kind == TokenKind::Ascending || current.kind == TokenKind::Descending { |
| 3769 | return Diagnostic::error("`ASC` and `DESC` must be used in `ORDER BY` statement") |
| 3770 | .with_location(location) |
| 3771 | .as_boxed(); |
| 3772 | } |
| 3773 | |
| 3774 | // Similar to SQL just `=` is used for equality comparisons |
| 3775 | if previous.kind == TokenKind::Equal && current.kind == TokenKind::Equal { |
| 3776 | return Diagnostic::error("Unexpected `==`, Just use `=` to check equality") |
| 3777 | .add_help("Try to remove the extra `=`") |
| 3778 | .with_location(location) |
| 3779 | .as_boxed(); |
| 3780 | } |
| 3781 | |
| 3782 | // `> =` the user may want to write `>=` |
| 3783 | if previous.kind == TokenKind::Greater && current.kind == TokenKind::Equal { |
| 3784 | return Diagnostic::error("Unexpected `> =`, do you mean `>=`?") |
| 3785 | .add_help("Try to remove space between `> =`") |
| 3786 | .with_location(location) |
| 3787 | .as_boxed(); |
| 3788 | } |
| 3789 | |
| 3790 | // `< =` the user may want to write `<=` |
| 3791 | if previous.kind == TokenKind::Less && current.kind == TokenKind::Equal { |
| 3792 | return Diagnostic::error("Unexpected `< =`, do you mean `<=`?") |
| 3793 | .add_help("Try to remove space between `< =`") |
| 3794 | .with_location(location) |
| 3795 | .as_boxed(); |
| 3796 | } |
| 3797 | |
| 3798 | // `> >` the user may want to write '>>' |
| 3799 | if previous.kind == TokenKind::Greater && current.kind == TokenKind::Greater { |
| 3800 | return Diagnostic::error("Unexpected `> >`, do you mean `>>`?") |
| 3801 | .add_help("Try to remove space between `> >`") |
| 3802 | .with_location(location) |
| 3803 | .as_boxed(); |
| 3804 | } |
| 3805 | |
| 3806 | // `< <` the user may want to write `<<` |
| 3807 | if previous.kind == TokenKind::Less && current.kind == TokenKind::Less { |
| 3808 | return Diagnostic::error("Unexpected `< <`, do you mean `<<`?") |
| 3809 | .add_help("Try to remove space between `< <`") |
| 3810 | .with_location(location) |
| 3811 | .as_boxed(); |
| 3812 | } |
no test coverage detected
searching dependent graphs…