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

Typeset built-in for variables #315

Merged
merged 7 commits into from
Nov 4, 2023
Merged

Typeset built-in for variables #315

merged 7 commits into from
Nov 4, 2023

Conversation

magicant
Copy link
Owner

@magicant magicant commented Nov 3, 2023

This pull request implements the typeset built-in for modifying and showing variables.
Operations on functions are not handled in this pull request.

Summary by CodeRabbit

  • New Features
    • Introduced a new built-in utility "typeset" for defining and manipulating shell variables and functions.
    • Added the ability to print variable attributes and values.
    • Implemented variable assignment and attribute application with error handling.
    • Introduced a new module for parsing command line arguments for the typeset command.
  • Bug Fixes
    • Added conversion functions between boolean values and the State enum to prevent type errors.
  • Tests
    • Added several tests to cover the new functionality and error handling.

@magicant magicant added the enhancement New feature or request label Nov 3, 2023
@magicant magicant self-assigned this Nov 3, 2023
Copy link

coderabbitai bot commented Nov 3, 2023

Walkthrough

The changes introduce a new built-in utility called "typeset" to the yash shell. This utility is used to define and manipulate shell variables and functions. The changes include the addition of new modules, types, and structs, as well as updates to existing ones. The new functionality includes parsing command line arguments, setting variables and functions, and printing variable attributes and values.

Changes

File Summary
yash-builtin/src/lib.rs Added a new module typeset with a main function that returns a Future wrapped in a Box.
yash-builtin/src/typeset.rs Introduced the typeset built-in command with its syntax, options, operands, and execution logic.
yash-builtin/src/typeset/print_variables.rs Updated PrintVariables struct to print variable attributes and values. Added tests for new functionality.
yash-builtin/src/typeset/set_functions.rs Updated SetFunctions struct with a new execute method.
yash-builtin/src/typeset/set_variables.rs Updated SetVariables struct with a new execute method for setting variables and applying attributes. Added tests for new functionality.
yash-builtin/src/typeset/syntax.rs Added a new module for parsing command line arguments for the typeset command. Included tests for the parsing and interpreting functions.
yash-env/src/option.rs Added implementation of the From<bool> and From<State> traits for the State enum and bool type respectively.

Poem

🍂 As autumn leaves fall, so does old code retire, 🍁

In its place, typeset rises, setting the shell on fire. 🔥

Variables and functions, now easier to set, 🎯

Making yash shell users, happier, I bet. 😊

So here's to the coders, working day and night, 🌙

Your efforts and dedication, are truly a sight. 👀

As the season changes, and the days grow shorter, 🌆

Your code keeps improving, like a flowing water. 💧


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.
  • @coderabbitai resolve to resolve all the CodeRabbit review comments.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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

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.

Review Status

Actionable comments generated: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 8e2bcac and 08bb265.
Files selected for processing (7)
  • yash-builtin/src/lib.rs (3 hunks)
  • yash-builtin/src/typeset.rs (1 hunks)
  • yash-builtin/src/typeset/print_variables.rs (1 hunks)
  • yash-builtin/src/typeset/set_functions.rs (1 hunks)
  • yash-builtin/src/typeset/set_variables.rs (1 hunks)
  • yash-builtin/src/typeset/syntax.rs (1 hunks)
  • yash-env/src/option.rs (1 hunks)
Files not reviewed due to errors (1)
  • yash-builtin/src/typeset/syntax.rs (Error: diff too large)
Files skipped from review due to trivial changes (1)
  • yash-env/src/option.rs
Additional comments: 16
yash-builtin/src/typeset/set_functions.rs (1)
  • 20-26: The execute method is currently unimplemented. Ensure that this is part of the plan and that it will be implemented in the future. If this method is called before it's implemented, it will panic at runtime.
pub fn execute(self, functions: &mut FunctionSet) -> Result<String, Vec<ExecuteError>> {
    _ = functions;
    todo!()
}
yash-builtin/src/lib.rs (3)
  • 57-63: The new typeset module is added to the list of modules. Ensure that the module is correctly implemented and that it doesn't conflict with existing modules.

  • 71-75: The Elective type is imported and used in the BUILTINS array. Ensure that the Elective type is correctly defined and used.

  • 170-176: The typeset command is added to the BUILTINS array. Ensure that the typeset::main function is correctly implemented and that it doesn't conflict with existing commands.

yash-builtin/src/typeset/set_variables.rs (4)
  • 1-15: The license and copyright notice is correctly placed at the top of the file.

  • 17-26: The From trait is correctly implemented for converting Scope to yash_env::variable::Scope.

  • 29-81: The execute method in the SetVariables struct is logically sound. It correctly handles variable assignment, attribute application, and error handling. The use of a vector to collect errors allows for multiple error reporting, which is a good practice.

  • 84-376: The unit tests are comprehensive and cover a wide range of scenarios, including setting local and global variables, setting variables to read-only, exporting variables, unsetting read-only attributes, overwriting read-only variables, hiding read-only variables, and combinations of read-only attributes. The tests use assertions to verify the expected outcomes, which is a good practice.

yash-builtin/src/typeset/print_variables.rs (6)
  • 1-15: The license and copyright notice is correctly placed at the top of the file.

  • 17-19: The necessary modules and types are correctly imported.

  • 21-48: The execute function correctly handles both cases where self.variables is empty and when it's not. It also correctly returns either the output string or a vector of ExecuteError if there are any errors.

  • 52-90: The print_one function correctly formats a variable for printing based on its attributes.

  • 92-109: The AttributeOption struct and its Display implementation are correctly defined.

  • 111-508: The tests cover a wide range of scenarios and correctly assert the expected results. However, the test on line 237 is ignored with a note that it needs VariableSet::get_scoped. Ensure that this is implemented and the test is enabled before merging.

yash-builtin/src/typeset.rs (2)
  • 1-541: The documentation is comprehensive and well-written. It provides a clear understanding of the typeset command's behavior, options, and error handling. The code structure is modular, with separate modules for different functionalities (print_variables, set_functions, set_variables, syntax). The use of enums (VariableAttr, Scope, FunctionAttr, Command, ExecuteError) provides a clear representation of the different states and behaviors. Error handling is also well-implemented with the use of the thiserror crate and custom error types. The execute method in the Command enum is a good example of using Rust's pattern matching feature for handling different command types. Overall, the code is well-structured, maintainable, and follows Rust's best practices.

  • 541-541: The main function is well-structured and handles different outcomes of the syntax::parse and syntax::interpret functions. It also handles the result of the command.execute(env) call, outputting the result or reporting errors as needed. This function provides a good example of Rust's error handling and pattern matching features.

Self::SetVariables(command) => command.execute(env),
Self::PrintVariables(command) => command.execute(&env.variables),
Self::SetFunctions(command) => command.execute(&mut env.functions),
Self::PrintFunctions(command) => todo!("{command:?}"), // command.execute(env),
Copy link

@coderabbitai coderabbitai bot Nov 3, 2023

Choose a reason for hiding this comment

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

The PrintFunctions variant in the execute method is currently not implemented. Ensure to implement this before merging the code.

- Self::PrintFunctions(command) => todo!("{command:?}"), // command.execute(env),
+ Self::PrintFunctions(command) => command.execute(env),

Commitable suggestion (Beta)
Suggested change
Self::PrintFunctions(command) => todo!("{command:?}"), // command.execute(env),
Self::PrintFunctions(command) => command.execute(env),

Copy link
Owner Author

Choose a reason for hiding this comment

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

I'm going to implement it in another pull request. Thanks!

Copy link

Choose a reason for hiding this comment

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

@magicant Understood! Feel free to reach out if you need any further assistance.

@magicant magicant mentioned this pull request Nov 3, 2023
14 tasks
@magicant magicant merged commit 9f396f5 into master Nov 4, 2023
5 checks passed
@magicant magicant deleted the typeset-builtin branch November 4, 2023 16:06
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.

None yet

1 participant