I play with vim-ruby indent, and there are quite complex regular expressions there:
" Regex used for words that, at the start of a line, add a level of indent.
let s:ruby_indent_keywords = '^\s*\zs\<\%(module\|class\|def\|if\|for' .
\ '\|while\|until\|else\|elsif\|case\|when\|unless\|begin\|ensure' .
\ '\|rescue\):\@!\>' .
\ '\|\%([=,*/%+-]\|<<\|>>\|:\s\)\s*\zs' .
\ '\<\%(if\|for\|while\|until\|case\|unless\|begin\):\@!\>'
Using the vim documentation, I decrypted it to mean:
start-of-line <any number of spaces> <start matching> <beginning of a word> /atom
<one of provided keywords> <colon character> <nothing> <end of word> ...
I have some doubts:
- Does this really match ':'? This doesn't seem to be the case, but I see nothing about the fact that the colon is a special character in regular expressions.
- Why does it exist
\zs(start of a match) and not \ze(end of a match)? - what is he doing \%()? Is this just some form of grouping?
source
share