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

Optionally use sed extended regex syntax #453

Merged
merged 5 commits into from
Sep 11, 2024

Conversation

hdwalters
Copy link
Contributor

Fixes #444.

src/std/text.ab Outdated Show resolved Hide resolved
// abc[123]def

main {
echo replace_regex("abc123def", "([0-9]+)", "[\1]", true)
Copy link
Member

Choose a reason for hiding this comment

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

This test would fail on a machine that does not support the new flag, right? Can we at least write a note somewhere or maybe even skip this test?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would prefer to keep the test, because it confirms that on systems which do support -E or -r, the right option is being used. And while Amber may be run on older systems, I doubt that anyone will run cargo test on them. Would you be happy with a comment in the test file?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah... I think that we should create some syntax for interfacing commands given different versions and os's. This way we could just run the sed through that interface and never worry

Copy link
Contributor Author

@hdwalters hdwalters Sep 5, 2024

Choose a reason for hiding this comment

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

I think that we should create some syntax for interfacing commands given different versions and os's

Makes sense, would need to give it some thought, but happy to discuss. In the meantime, I've added this warning comment. Does this resolve your immediate request?

// This will fail on any system where sed does not support extended
// regex syntax, via "-r" on GNU sed and "-E" on all other versions.

src/std/text.ab Outdated Show resolved Hide resolved
src/std/text.ab Outdated Show resolved Hide resolved
Copy link
Member

@Ph0enixKM Ph0enixKM left a comment

Choose a reason for hiding this comment

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

LGTM

@Ph0enixKM Ph0enixKM merged commit 1810a90 into amber-lang:master Sep 11, 2024
1 check passed
@hdwalters hdwalters deleted the use-sed-extended-regex branch September 11, 2024 20:21
Mte90 pushed a commit to Mte90/Amber that referenced this pull request Sep 19, 2024
* Optionally use sed extended regex syntax.

* Update src/std/text.ab

Co-authored-by: Phoenix Himself <pkaras.it@gmail.com>

* Add comment stating that sed extended regex may fail on some older Linux variants.

* Change regex used to detect GNU sed.

* Remove duplicate unsafe from stdlib function.

---------

Co-authored-by: Phoenix Himself <pkaras.it@gmail.com>
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.

[Feature] Ability to use extended regex syntax in sed
4 participants