Skip to content

Make Parser::maybe_parse pub #1364

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

Merged
merged 1 commit into from
Aug 7, 2024
Merged

Conversation

Jesse-Bakker
Copy link
Contributor

@Jesse-Bakker Jesse-Bakker commented Aug 6, 2024

This method is useful for wrapping sqlparser's parser to parse custom syntax, falling back to the upstream implementation. For example:

enum CustomStatement {
    CreateCustom {
        or_replace: bool,
        thingy: String,
    },
    Statement(Statement),
}

fn parse_custom_create(parser: &mut Parser) -> Result<CustomStatement, ParserError> {
    if let Some(custom) = parser.maybe_parse(|parser| {
        let or_replace = parser.parse_keywords(&[Keyword::OR, Keyword::REPLACE]);
        parse_create_custom(or_replace)
    }) {
        Ok(custom)
    } else {
        Ok(CustomStatement::Statement(parser.parse_create()?))
    }
}

Without access to maybe_parse, this would not be possible be very inconvenient

@coveralls
Copy link

Pull Request Test Coverage Report for Build 10261971206

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 89.235%

Totals Coverage Status
Change from base Build 10235939983: 0.0%
Covered Lines: 27472
Relevant Lines: 30786

💛 - Coveralls

Copy link
Contributor

@iffyio iffyio left a comment

Choose a reason for hiding this comment

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

LGTM! cc @alamb

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

🚀

@alamb alamb merged commit 2d4b9b3 into apache:main Aug 7, 2024
10 checks passed
ayman-sigma pushed a commit to sigmacomputing/sqlparser-rs that referenced this pull request Nov 19, 2024
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

Successfully merging this pull request may close these issues.

4 participants