Skip to content

Implement address compilation#57

Merged
sylvestre merged 16 commits intouutils:mainfrom
dspinellis:compile-specs
May 3, 2025
Merged

Implement address compilation#57
sylvestre merged 16 commits intouutils:mainfrom
dspinellis:compile-specs

Conversation

@dspinellis
Copy link
Copy Markdown
Collaborator

No description provided.

@sylvestre sylvestre requested review from Copilot April 27, 2025 12:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces enhancements for address compilation in sed by adding a new module, additional functionality, and documentation updates.

  • Added a new module (delimited_parser) in sed.rs
  • Added a new "retreat" helper function to ScriptCharProvider
  • Provided a default implementation for Command and updated the README with new extension details

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.

File Description
src/uu/sed/src/sed.rs New module added to support delimited parsing functionality.
src/uu/sed/src/script_char_provider.rs Added a new retreat function to adjust the character position.
src/uu/sed/src/command.rs Introduced a default implementation for Command.
README.md Enhanced documentation with extension details.
Comments suppressed due to low confidence (1)

src/uu/sed/src/script_char_provider.rs:32

  • Consider adding unit tests for the new 'retreat' function to verify its behavior on boundary conditions (e.g., when n is greater than or equal to the current position).
pub fn retreat(&mut self, n: usize) {

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@dspinellis
Copy link
Copy Markdown
Collaborator Author

I also added unit tests for the new 'retreat' function.

value: AddressValue::LineNumber(number),
})
}
_ => panic!("invalid context address"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

panic a bit violent in rust :)
also, you might want to add the line info to help with debugging

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It's an internal error; it shouldn't happen. The code reaches this point only when is_address_char has detected one of the preceding characters.

.and_then(char::from_u32)
{
Some(decoded) => Some(decoded),
None => panic!("Unable to decode numeric character escape."),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same comment about the panic :)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Same here: preceding lines have already verified that this is a valid sequence for the specified radix. The panic should only be triggered if there's a code error not a user error.

Comment thread src/uu/sed/src/delimited_parser.rs Outdated
Comment on lines +93 to +96
let mut c = x;
if c.is_ascii_lowercase() {
c = c.to_ascii_uppercase();
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

maybe just do

Suggested change
let mut c = x;
if c.is_ascii_lowercase() {
c = c.to_ascii_uppercase();
}
let c = x.to_ascii_uppercase();

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thanks, fixed!

Comment thread src/uu/sed/src/script_char_provider.rs Outdated
Comment on lines +33 to +37
if n > self.pos {
self.pos = 0;
} else {
self.pos -= n;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if n > self.pos {
self.pos = 0;
} else {
self.pos -= n;
}
self.pos = self.pos.saturating_sub(n);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Didn't know that; thanks! Fixed.

@sylvestre
Copy link
Copy Markdown
Contributor

kudos for all the tests :)

@dspinellis
Copy link
Copy Markdown
Collaborator Author

I pushed a fix addressing the comments that needed fixing.

@sylvestre sylvestre merged commit 5a876ee into uutils:main May 3, 2025
14 checks passed
@codecov
Copy link
Copy Markdown

codecov Bot commented May 3, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 0.00%. Comparing base (540edf0) to head (e791a44).
Report is 36 commits behind head on main.

Additional details and impacted files
@@    Coverage Diff     @@
##   main   #57   +/-   ##
==========================
==========================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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