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

fix: adjust tag association in optional and repeat expressions #985

Merged
merged 4 commits into from
Mar 2, 2024

Conversation

tomtau
Copy link
Contributor

@tomtau tomtau commented Mar 1, 2024

fixes #984, fixes #982

Summary by CodeRabbit

  • New Features
    • Introduced grammar rule for expressions with optional components.
  • Tests
    • Added tests for new grammar rule parsing and multi-tag parsing with implicit whitespace handling.
  • Refactor
    • Enhanced expression generation logic for improved efficiency and token stream handling.

@tomtau tomtau added the pr label Mar 1, 2024
@tomtau tomtau requested a review from a team as a code owner March 1, 2024 06:17
@tomtau tomtau requested review from NoahTheDuke and removed request for a team March 1, 2024 06:17
Copy link
Contributor

coderabbitai bot commented Mar 1, 2024

Walkthrough

This update primarily addresses issues related to parsing grammar rules with optional components and tagging within expressions. It introduces new tests to ensure correctness in scenarios involving optional prefixes and suffixes, as well as multiple tags. The refactoring within the generator module aims to optimize expression handling, particularly for NodeTag cases, enhancing the efficiency of token stream generation. These changes collectively strive to fix bugs and improve the parsing capabilities of the system.

Changes

Files Change Summary
derive/tests/implicit.rs Added test test_implicit_whitespace_multitag for parsing with multiple tags.
derive/tests/opt.rs Introduces a test for parsing a specific grammar rule using the pest parser generator.
generator/src/generator.rs Refactored generate_expr and generate_expr_atomic functions to optimize OptimizedExpr handling.

Assessment against linked issues

Objective Addressed Explanation
Understand and fix the wrong tag association with optional expressions (#984) The changes do not directly address the issue of wrong tag association with optional expressions.
Clarify behavior of tags on rules yielding multiple pairs and ensure correct tag retrieval (#982) The changes address the need to handle multiple tags and improve tag retrieval in parsing rules.
Verify if the observed behaviors are bugs or limitations and improve documentation/implementation accordingly (#982, #984) While improvements have been made, further validation is needed to confirm if all issues are resolved.

Poem

In the code where bugs once dwelled,
A rabbit hopped, and spells it spelled.
🌟 With a twitch of nose, and a thump of feet,
Bugs vanished, and the code did greet.
A world so clear, with tags aligned,
Where expressions and rules, perfectly intertwined.
🐇 "Hop forward," it cheered, "to a future so bright,
Where parsing's a joy, and everything's right!"

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit-tests for this file.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit tests for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 2

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between a0a92fb and d55aa76.
Files selected for processing (4)
  • derive/tests/implicit.rs (1 hunks)
  • derive/tests/opt.pest (1 hunks)
  • derive/tests/opt.rs (1 hunks)
  • generator/src/generator.rs (2 hunks)
Additional comments: 3
derive/tests/opt.pest (1)
  • 1-8: The grammar definition in opt.pest correctly implements optional prefix and suffix components using ? to denote optionality. This change should address the incorrect tag assignment issue (Wrong tag associated with expression? #984) by explicitly defining the optional nature of STAR and DOT tokens with associated tags #prefix and #suffix. Ensure that the rest of the grammar and the parser logic correctly interpret these optional components and their tags.
generator/src/generator.rs (2)
  • 574-609: The refactoring for handling OptimizedExpr::NodeTag in generate_expr introduces a more structured approach to tagging nodes in optional (Opt) and repeat (Rep) expressions. This change is crucial for addressing the issues mentioned in the PR objectives, specifically the correct assignment of tags in these contexts. The use of state.tag_node(#tag) after the optional and repeat expressions ensures that tags are correctly applied, which aligns with the objectives of fixing tag association issues.

However, there are a few considerations:

  • Ensure that the performance impact of these changes is minimal. The additional calls to state.tag_node could potentially introduce overhead, especially in deeply nested or highly repetitive structures.
  • Verify that this approach does not introduce any unintended side effects, particularly in complex grammars where optional and repeat expressions are heavily used.

Overall, the changes appear to address the issues effectively, but it would be beneficial to conduct thorough testing with various grammars to confirm that the behavior aligns with expectations and does not introduce new issues.

  • 759-784: The changes to generate_expr_atomic for handling OptimizedExpr::NodeTag mirror those in generate_expr, focusing on the atomic context. This consistency between the handling of NodeTag in both atomic and non-atomic contexts is important for ensuring that tags are applied uniformly across different types of expressions.

Similar considerations apply here as with the changes in generate_expr:

  • The impact on performance should be monitored, especially for grammars that make extensive use of atomic expressions.
  • Comprehensive testing is necessary to ensure that these changes do not introduce unexpected behavior in complex grammars.

Given the alignment with the PR's objectives and the structured approach to handling tags, these changes are also approved. However, it's crucial to validate the implementation through testing.

derive/tests/opt.rs Outdated Show resolved Hide resolved
derive/tests/implicit.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between d55aa76 and 3f57932.
Files selected for processing (2)
  • derive/tests/implicit.rs (1 hunks)
  • derive/tests/opt.rs (1 hunks)
Files skipped from review as they are similar to previous changes (2)
  • derive/tests/implicit.rs
  • derive/tests/opt.rs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 3f57932 and c7c2ff0.
Files ignored due to path filters (7)
  • debugger/Cargo.toml is excluded by: !**/*.toml
  • derive/Cargo.toml is excluded by: !**/*.toml
  • generator/Cargo.toml is excluded by: !**/*.toml
  • grammars/Cargo.toml is excluded by: !**/*.toml
  • meta/Cargo.toml is excluded by: !**/*.toml
  • pest/Cargo.toml is excluded by: !**/*.toml
  • vm/Cargo.toml is excluded by: !**/*.toml
Files selected for processing (1)
  • derive/tests/opt.rs (1 hunks)
Files skipped from review as they are similar to previous changes (1)
  • derive/tests/opt.rs

Copy link
Member

@NoahTheDuke NoahTheDuke left a comment

Choose a reason for hiding this comment

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

Nice fix.

@tomtau tomtau merged commit 28c01cb into pest-parser:master Mar 2, 2024
9 checks passed
@tomtau tomtau deleted the repeat-tags branch March 2, 2024 00:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Wrong tag associated with expression? Tags on rules that can yield more than one pair
2 participants