Skip to content

Support /pattern/ and ?pattern? search addresses #7

Description

@anderix

ved's address parser recognizes line numbers, ., $, and current-relative
offsets, but not regex search addresses. GNU ed accepts /pattern/ and
?pattern? anywhere an address is allowed; ved reports them as an unknown
command.

$ ved
a
alpha
beta
.
/beta/p
? unknown command: /beta/p

GNU ed prints beta for the same input.

The BRE engine in src/bre.rs already provides the matching this needs, so the
work is in src/address.rs. Address gains a variant carrying the pattern and
a direction, parse_one recognizes the / and ? delimiters with backslash
escaping, and resolve_one scans forward or backward from the current line,
wrapping at the buffer ends the way ed does. Resolution would need the buffer's
text, which resolve_one already receives.

Two related cleanups belong with this work. src/address.rs carries a comment
saying search addresses "wait for slice 5 when the regex engine arrives" —
slice 5 shipped the engine without them, so the comment describes a plan rather
than the program, and it should state the present limitation instead. And the
README's "Limitations worth knowing" section lists the two intentional
ed-inherited limitations without mentioning this one; whether or not the
feature lands, that section should say search addresses are unsupported, since
the compatibility claim above it leads a reader to expect them.

Compound offset addressing ($-5, 5-3) is a separate gap in the same file
and is not covered here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions