MCPcopy Create free account
hub / github.com/AmrDeveloper/GQL / un_expected_expression_error

Function un_expected_expression_error

crates/gitql-parser/src/parser.rs:3755–3834  ·  view source on GitHub ↗
(tokens: &[Token], position: &usize)

Source from the content-addressed store, hash-verified

3753}
3754
3755fn 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 }

Callers 1

parse_primary_expressionFunction · 0.85

Calls 5

calculate_safe_locationFunction · 0.85
as_boxedMethod · 0.80
with_locationMethod · 0.80
add_helpMethod · 0.80
lenMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…