thimc / ed

go clone of ed, the standard UNIX text editor
MIT License
3 stars 0 forks source link

Getting `no match`... #1

Open elifarley opened 2 weeks ago

elifarley commented 2 weeks ago

Hi! Tack a lot for creating this ed clone. I need to include this in a code processing runtime (CEDARScript), but I could not get it to work.

Could you help me, please?

Here's the file that needs editing:

class BaseConverter:
    def encode(self, i):
        neg, value = self.convert(i, self.decimal_digits, self.digits, "-")
    def decode(self, s):
        neg, value = self.convert(s, self.digits, self.decimal_digits, self.sign)
def convert(self, number, from_digits, to_digits, sign):

And here's the file with the editing script:

H
/def convert/s/self, //
/self.convert/s/self\.(convert)/\1/g
w
q

And this is the sequence of commands I tried:

ed 1.py < script.ed
287
script, line 2: no match
script, line 2: no match
286

Now, if I use ed that comes in MacOS X, I get a different error:

286
?
script, line 3: no match

Do you have any idea of what's wrong here?

Thank you!

elifarley commented 2 weeks ago

If I use an address range, it works:

,/def convert/s/self, //

But I need to perform the replacements only on each line that matches /def convert/

elifarley commented 2 weeks ago

The correct syntax is:

H
g/def convert/s/self, //
g/self\.convert/s/self\.\(convert\)/\1/g
w
q

Standard ed performs the changes as expected and outputs:

286
270

Your ed command doesn't change anything and then outputs:

287
def convert(self, number, from_digits, to_digits, sign):
        neg, value = self.convert(i, self.decimal_digits, self.digits, "-")
        neg, value = self.convert(s, self.digits, self.decimal_digits, self.sign)
286
thimc commented 2 weeks ago

Hi, thanks for the feedback. I will look in to it, I am quite surprised that the tests aren't failing for the global command but I guess there are edge cases.

EDIT:

Actually the correct syntax is:

H
g/def convert/s/self, //
g/self\.convert/s/self\.(convert)/\1/g
w
q

Escaping the parentheses is not needed in RE2, but I am aware that the substitute command isn't working as expected.