Skip to content

The redundant punctuation in "expected()" #1433

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Fischer0522 opened this issue Sep 19, 2024 · 4 comments
Closed

The redundant punctuation in "expected()" #1433

Fischer0522 opened this issue Sep 19, 2024 · 4 comments

Comments

@Fischer0522
Copy link
Contributor

The expected() function will format the message in accordance with format!("Expected: {expected}, found: {found}"). However, when expected() is called by parse_prefix() at line 1254 in mod.rs, the parameter is "an expression:". Consequently, the formatted message is "Expected: an expression:, found: EOF". The ":," appears redundant.

Related code:

    /// Report `found` was encountered instead of `expected`
    pub fn expected<T>(&self, expected: &str, found: TokenWithLocation) -> Result<T, ParserError> {
        parser_err!(
            format!("Expected: {expected}, found: {found}"),
            found.location
        )
    }

// in parse_prefix()
            _ => self.expected("an expression:", next_token),
@Fischer0522
Copy link
Contributor Author

Perhaps “Expected: an expression, found: EOF” is a more appropriate format. Please review it @alamb

@git-hulk
Copy link
Member

git-hulk commented Sep 19, 2024

It should be good to remove the redundant :. Also, maybe you can check if other places which use expect have similar issues.

@Fischer0522
Copy link
Contributor Author

Fischer0522 commented Sep 19, 2024

It should be good to remove the redundant :. Also, maybe you can check if other places which use expect have similar issues.

I have checked all places that use expect. This is the only place where this problem occurs. please check this pr #1434

@git-hulk
Copy link
Member

@Fischer0522 This issue can be closed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants