Monday, February 18, 2013

Re: trouble with pattern, character collections

On 18.02.13 23:06, Christian Brabandt wrote:
> No, it is because "\n" is evaluated to a true line feed, so "[^\n]"
> matches anything but ASCII NUL and ASCII 10, while '[^\n]' matches
> anything but ASCII NUL (which is used internally by Vim to distinguish
> lines from each other (e.g. a line seperator), so that a . matches
> anyhing in the buffer but the line seperator)
>
> > If so which is the best way to fix this - and which should be the way to
> > express [^\n] meaning do not match \n rather than behave like '.' then ?

Vim already uses '$' for EOL, documented at ":h $", which even seems to
offer the synonym "<End>". Vim already has '.' to mean '.', so does not
need <elephant> for the same. So why do it???

> [^\n] should always behave like '.'

No, sorry, only in a line devoid of newlines. By definition.
In regex terms, i.e the user view, [^\n] may match anything other than a
newline, while '.' may match any single character. Only if newlines have
been stripped in the internal line representation, and e.g. replaced
with NUL, can '.' legitimately fail to match \n. Otherwise, we can only
reasonably say the [^\n] should NOT always behave like '.'

In contrast, "[^\n]" _is_ identical to '[^\n]' in regex syntax, so must
be identical in behaviour, devoid of even subtle differences, in any
context.

On 18.02.13 23:38, Marc Weber wrote:
> I'm *not* talking about internals. I'm talking the user interface you
> and me and new users are faced with every day. So help me think about
> whether there is a way to improve the situation.
>
> So why should anybody write [^\n] if you can use '.'? So why make [^\n]
> behave the same way? Why not make it raise an error such as:
>
> E99999: For odd reasons you should try "[\n]" instead of '[^\n]' and be
> done. True reason see long reply by Christian on ml ..

Or E99999: Unsupported syntax. Vim fails to give rational syntax-relevant
effect to this regex. Try <whatever> instead.

Sorry, [^\n] can never match \n ; not even in pink. That is broken
behaviour.

Erik

--
Why make things difficult, when it is possible to make them cryptic
and totally illogical, with just a little bit more effort?"
- A. P. J.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: