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

Allow esac as the first pattern of a case branch #426

Merged
merged 1 commit into from
Nov 9, 2024
Merged

Conversation

magicant
Copy link
Owner

@magicant magicant commented Nov 9, 2024

POSIX has been changed to allow esac as the first pattern of a case
branch. This commit implements this change in the parser.

Summary by CodeRabbit

Release Notes for Version 0.1.1

  • New Features

    • The shell now accepts esac as the first pattern in a case branch, aligning with POSIX.1-2024 standards.
    • Enhanced bg built-in to correctly reflect the process ID of background jobs.
    • Modified exec built-in to prevent shell exit on command not found in interactive mode.
  • Bug Fixes

    • Improved error handling for parameter expansions and syntax errors.
    • Updated exit statuses for scripts that cannot be opened, now compliant with POSIX.
  • Tests

    • Added new test cases for the case command to ensure compliance with various scenarios and edge cases.

POSIX has been changed to allow `esac` as the first pattern of a case
branch. This commit implements this change in the parser.
@magicant magicant added the enhancement New feature or request label Nov 9, 2024
@magicant magicant self-assigned this Nov 9, 2024
Copy link

coderabbitai bot commented Nov 9, 2024

Walkthrough

The pull request introduces several changes across the yash-cli and yash-syntax projects to enhance compliance with POSIX.1-2024 standards. Key modifications include allowing esac as the first pattern in case branches, updating built-in commands like bg and exec, and improving error handling. Additionally, new test cases for the case command have been added to validate these changes. The changelog files for both projects have been updated to reflect these modifications and their implications.

Changes

File Path Change Summary
yash-cli/CHANGELOG-bin.md Updated changelog for version 0.1.1, detailing changes to shell syntax and built-ins for POSIX compliance.
yash-cli/tests/scripted_test/case-p.sh Added new test cases for case command; modified existing tests to validate esac handling and redirection.
yash-syntax/CHANGELOG.md Updated changelog for version 0.12.1, noting changes to case_item method and deprecation of EsacAsPattern.
yash-syntax/src/parser/case.rs Modified case_item method to accept esac as a valid pattern; streamlined error handling logic.
yash-syntax/src/parser/error.rs Introduced deprecated EsacAsPattern variant in SyntaxError; updated error messages and labels accordingly.

Possibly related PRs

Poem

In the shell where rabbits play,
esac leads the way! 🐇
Patterns dance, errors cease,
With each change, we find our peace.
Tails twitch in joyful cheer,
For POSIX standards, we hold dear! 🌟


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>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • 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 testing code 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@magicant magicant mentioned this pull request Nov 9, 2024
36 tasks
Copy link

@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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (6)
yash-cli/CHANGELOG-bin.md (1)

15-17: LGTM with a minor suggestion.

The changelog entry accurately documents the POSIX.1-2024 compliance change and provides a clear example. Consider adding a reference to the specific POSIX.1-2024 section that defines this behavior, similar to how other entries in the changelog reference POSIX (e.g., the entry in version 0.1.0-beta.1).

Apply this diff to enhance the documentation:

 - The shell's syntax now allows `esac` as the first pattern of a case branch
   as in `case esac in (esac|case) echo ok; esac`. Previously, it was a syntax
-  error, but POSIX.1-2024 allows it.
+  error, but POSIX.1-2024 <insert-section-reference> allows it.
yash-cli/tests/scripted_test/case-p.sh (2)

336-341: LGTM! Consider adding edge cases.

The test case correctly validates the new POSIX-compliant behavior of allowing esac as the first pattern.

Consider adding test cases for:

  • Multiple patterns including esac (e.g., esac|foo)
  • Quoted esac pattern (e.g., "esac")
  • Pattern with esac as a substring (e.g., fooesac)
🧰 Tools
🪛 Shellcheck

[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 337-337: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


Line range hint 347-355: Consider cleaning up temporary files.

The test case correctly validates redirection handling. However, the temporary file 'redir_out' should be cleaned up after the test to prevent test pollution.

Consider adding cleanup:

 case $(echo foo >&2) in
     $(echo bar >&2)) echo baz >&2;;
 esac 2>redir_out
 cat redir_out
+rm -f redir_out
 __IN__
 foo
 bar
 baz
 __OUT__
🧰 Tools
🪛 Shellcheck

[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 337-337: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 343-343: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 343-343: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 343-343: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)

yash-syntax/CHANGELOG.md (1)

12-15: Consider adding POSIX reference for better traceability.

The changelog entry clearly explains the change and rationale. To enhance traceability, consider adding a reference to the specific POSIX.1-2024 section that documents this requirement.

yash-syntax/src/parser/error.rs (1)

223-223: Consider updating the error messages for consistency.

While the error messages for the deprecated EsacAsPattern variant are technically incorrect now (since esac can be the first pattern), this is acceptable as the variant is deprecated and will be removed in a future version.

However, consider adding a comment explaining why these messages are kept despite being incorrect, to prevent confusion for future maintainers.

    #[allow(deprecated)]
-   EsacAsPattern => "`esac` cannot be the first of a pattern list",
+   // Note: This message is kept for backward compatibility despite being incorrect
+   // as `esac` is now allowed as the first pattern (POSIX.1-2024)
+   EsacAsPattern => "`esac` cannot be the first of a pattern list",

Also applies to: 295-295

yash-syntax/src/parser/case.rs (1)

65-65: Consider adding a comment about POSIX compliance

While the implementation is correct, it would be helpful to add a comment explaining that esac is allowed as a pattern to comply with POSIX.1-2024 standards.

+    // POSIX.1-2024 allows 'esac' as a valid pattern in case branches
     Token(_) => next_token.word,
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e7edd6a and a213aba.

📒 Files selected for processing (5)
  • yash-cli/CHANGELOG-bin.md (1 hunks)
  • yash-cli/tests/scripted_test/case-p.sh (1 hunks)
  • yash-syntax/CHANGELOG.md (1 hunks)
  • yash-syntax/src/parser/case.rs (2 hunks)
  • yash-syntax/src/parser/error.rs (3 hunks)
🧰 Additional context used
🪛 Shellcheck
yash-cli/tests/scripted_test/case-p.sh

[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 337-337: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)

🔇 Additional comments (6)
yash-cli/tests/scripted_test/case-p.sh (1)

Line range hint 342-346: LGTM! Good backward compatibility test.

The test case properly validates that esac continues to work as a non-first pattern, ensuring backward compatibility.

🧰 Tools
🪛 Shellcheck

[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 337-337: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 337-337: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 343-343: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)


[warning] 343-343: This word is constant. Did you forget the $ on a variable?

(SC2194)


[warning] 343-343: Use semicolon or linefeed before 'esac' (or quote to make it literal).

(SC1010)

yash-syntax/CHANGELOG.md (2)

19-24: LGTM!

The deprecation notice is well-documented with a clear explanation of why the error variant is no longer needed.


12-24: Version and status are appropriate.

The version bump to 0.12.1 is appropriate for these backward-compatible changes, and marking it as "Unreleased" is correct for work in progress.

yash-syntax/src/parser/error.rs (1)

138-138: LGTM! Good use of deprecation.

The addition of the deprecated EsacAsPattern variant is a clean way to handle the transition to allowing esac as a pattern while maintaining backward compatibility.

yash-syntax/src/parser/case.rs (2)

65-65: Implementation correctly allows esac as a pattern

The changes align with POSIX.1-2024 requirements by allowing esac as a valid pattern in case branches. The implementation maintains proper error handling while accommodating this new valid pattern case.

Also applies to: 319-322


319-322: Test coverage is comprehensive

The test suite thoroughly validates the new behavior, including:

  • Basic usage of esac as a pattern
  • Integration with existing pattern matching features
  • Edge cases and error conditions

@magicant magicant merged commit 7d2a289 into master Nov 9, 2024
8 checks passed
@magicant magicant deleted the esac-pattern branch November 9, 2024 13:47
This was referenced Nov 9, 2024
@coderabbitai coderabbitai bot mentioned this pull request Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant