Skip to content
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

refactor(parser): introduce a compactible layer for parser v2 to call v1 #17036

Merged
merged 1 commit into from
May 31, 2024

Conversation

TennyZhuang
Copy link
Contributor

@TennyZhuang TennyZhuang commented May 31, 2024

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

  • Introduce ParseV1 as a compatible trait for parser v2
  • Write expr_case as an example

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added test labels as necessary. See details.
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

👀 May I know the relationship versus #17019?

@TennyZhuang
Copy link
Contributor Author

TennyZhuang commented May 31, 2024

👀 May I know the relationship versus #17019?

The PR is based on that.

#17019 replace the underlying input stream of parser v2 from &[TokenWithLocation] to parser_v1::Parser<'a>.

The PR introduce a compatible trait, to allow S: TokenStream export underlying parser_v1::Parser, and call methods on it.

Based on the PR, we can refactor the recursive terms step by step. E.g., we create a fake v2 expr which calls v1 internally, then we can write a real v2 expr_case based on the fake expr.

@TennyZhuang TennyZhuang enabled auto-merge May 31, 2024 07:16
Copy link
Contributor

@wangrunji0408 wangrunji0408 left a comment

Choose a reason for hiding this comment

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

Rest LGTM!

Comment on lines +30 to +35
pub fn expr_case<S>(input: &mut S) -> PResult<Expr>
where
S: TokenStream,
{
let parse = (
opt(expr),
Copy link
Contributor

Choose a reason for hiding this comment

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

In terms of semantics, this function should start parsing from CASE and the caller should not consume CASE before calling it.

Suggested change
pub fn expr_case<S>(input: &mut S) -> PResult<Expr>
where
S: TokenStream,
{
let parse = (
opt(expr),
pub fn expr_case<S>(input: &mut S) -> PResult<Expr>
where
S: TokenStream,
{
let parse = (
Keyword::CASE,
opt(expr),

Copy link
Contributor Author

@TennyZhuang TennyZhuang May 31, 2024

Choose a reason for hiding this comment

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

Unfortunately we have to following the v1's behavior.

Another problem is dispatch! is much more efficient than alt, even in v2, using the style can achieve best performance.

Copy link
Contributor Author

@TennyZhuang TennyZhuang May 31, 2024

Choose a reason for hiding this comment

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

The only thing I can do is rename it to expr_case_suffix or expr_case_rest, but seems too verbose.

Copy link
Contributor

@wangrunji0408 wangrunji0408 May 31, 2024

Choose a reason for hiding this comment

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

Okay let's correct this later.

dispatch! can also be used with peek(keyword) which doesn't consume the token. 😄

@TennyZhuang TennyZhuang added this pull request to the merge queue May 31, 2024
Merged via the queue into risingwavelabs:main with commit a86c6ac May 31, 2024
31 of 32 checks passed
@TennyZhuang TennyZhuang deleted the parser-v2-compact-v1 branch May 31, 2024 08:27
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.

3 participants