dalance / amber

A code search / replace tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Brackets in file alter regex behaviour

ngirard opened this issue · comments

Using Anchor v0.5.5 (precompiled binary) on Ubuntu 20.04, and testing it against Ripgrep 11.0.2.

Doing

f=$(tempfile)
cat <<EOF > "$f"
> []
> Test
> EOF

ambs -r -- '^Test' "$f"
ambs -r -- 'Test$' "$f"

outputs nothing, while

rg -s --no-heading --with-filename --no-line-number -- '^Test' "$f"
rg -s --no-heading --with-filename --no-line-number -- 'Test$' "$f"

outputs

/tmp/fileyO3IXf:Test
/tmp/fileyO3IXf:Test

Any update...?
I really wish I could use Amber ;-)

Cheers

Sorry for the late reply.
By default, regex of amber is single-line mode. So ^ and $ match the beginning of text and the end of text.
If (?m) is used, regex becomes multi-line mode.

f=$(mktemp)
cat << EOF > "$f"
[]
Test
EOF

ambs -r -- '(?m)^Test' "$f"
ambs -r -- '(?m)Test$' "$f"

Thanks for your feedback !
Unfortunately it doesn't make sense to me, why the multiline mode would be needed for matching '^Test' or 'Test$'.

As you can see, Ripgrep's invocations worked just fine, while by default Ripgrep's multiline mode is off.

Egrep also works just fine with these simple invocations:

egrep '^Test' "$f"
egrep 'Tests' "$f"

Sd works just fine as-is, without triggering its multi-line mode:

sd -p 'Test$' "Replacement" "$f"
sd -p '^Test' "Replacement" "$f"

I enabled multi-line mode, and released v0.5.6.

Using the freshest pre-compiled binaries (v0.5.7) on Ubuntu 20.04, and running this issue's minimal example, I'm getting:

ambs -r -- '^Test' "$f"
thread 'main' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'matcher' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalidthread 'matcher' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', thread '/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658', :/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rsfinderthread '9' panicked at ':
attempted to leave type `internal::Local` uninitialized, which is invalid658

ambs -r -- 'Test$' "$f"
thread 'main' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

FWIW:

RUST_BACKTRACE=1 ambs -r -- '^Test' "$f"
thread 'thread 'main' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
stack backtrace:
matcher' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalidthread '', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658printer' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:658:9
thread 'matcher' panicked at 'attempted to leave type `internal::Local` uninitialized, which is invalid', /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs::658:9
9
thread 'finder' panicked at 'thread 'attempted to leave type `internal::Local` uninitialized, which is invalid', sorter' panicked at '/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:attempted to leave type `internal::Local` uninitialized, which is invalid', 658:/rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/mem/mod.rs:9
658:9
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::panic_fmt
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:85
   2: core::panicking::panic
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/core/src/panicking.rs:50
   3: <crossbeam_epoch::internal::Local as crossbeam_epoch::sync::list::IsElement<crossbeam_epoch::internal::Local>>::entry_of
   4: std::thread::local::fast::Key<T>::try_initialize
   5: crossbeam_channel::channel::Sender<T>::send
   6: ambs::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
stack backtrace:
   0: rust_begin_unwind
             at /rustc/7eac88abb2e57e752f3302f02be5f3ce3d7adfb4/library/std/src/panicking.rs:483
   1: core::panicking::

A dependent crate seems to break at 1.48.0.
I fixed it, and released v0.5.8.

Indeed, v0.5.8 works like a charm ! Thank you very much !