Some checks failed
Detach Plugins / check (FlyGrep.vim) (push) Has been cancelled
Detach Plugins / check (GitHub.vim) (push) Has been cancelled
Detach Plugins / check (JavaUnit.vim) (push) Has been cancelled
Detach Plugins / check (SourceCounter.vim) (push) Has been cancelled
Detach Plugins / check (cpicker.nvim) (push) Has been cancelled
Detach Plugins / check (dein-ui.vim) (push) Has been cancelled
Detach Plugins / check (git.vim) (push) Has been cancelled
Detach Plugins / check (iedit.vim) (push) Has been cancelled
Detach Plugins / check (scrollbar.vim) (push) Has been cancelled
Detach Plugins / check (vim-chat) (push) Has been cancelled
Detach Plugins / check (vim-cheat) (push) Has been cancelled
Detach Plugins / check (vim-todo) (push) Has been cancelled
Detach Plugins / check (xmake.vim) (push) Has been cancelled
test / Linux (nvim, nightly) (push) Has been cancelled
test / Linux (nvim, v0.3.8) (push) Has been cancelled
test / Linux (nvim, v0.4.0) (push) Has been cancelled
test / Linux (nvim, v0.4.2) (push) Has been cancelled
test / Linux (nvim, v0.4.3) (push) Has been cancelled
test / Linux (nvim, v0.4.4) (push) Has been cancelled
test / Linux (nvim, v0.5.0) (push) Has been cancelled
test / Linux (nvim, v0.5.1) (push) Has been cancelled
test / Linux (nvim, v0.6.0) (push) Has been cancelled
test / Linux (nvim, v0.6.1) (push) Has been cancelled
test / Linux (nvim, v0.7.0) (push) Has been cancelled
test / Linux (nvim, v0.7.2) (push) Has been cancelled
test / Linux (nvim, v0.8.0) (push) Has been cancelled
test / Linux (nvim, v0.8.1) (push) Has been cancelled
test / Linux (nvim, v0.8.2) (push) Has been cancelled
test / Linux (nvim, v0.8.3) (push) Has been cancelled
test / Linux (nvim, v0.9.0) (push) Has been cancelled
test / Linux (nvim, v0.9.1) (push) Has been cancelled
test / Linux (true, vim, v7.4.052) (push) Has been cancelled
test / Linux (true, vim, v7.4.1689) (push) Has been cancelled
test / Linux (true, vim, v7.4.629) (push) Has been cancelled
test / Linux (true, vim, v8.0.0027) (push) Has been cancelled
test / Linux (true, vim, v8.0.0183) (push) Has been cancelled
test / Linux (vim, nightly) (push) Has been cancelled
test / Linux (vim, v8.0.0184) (push) Has been cancelled
test / Linux (vim, v8.0.1453) (push) Has been cancelled
test / Linux (vim, v8.1.2269) (push) Has been cancelled
test / Linux (vim, v8.2.2434) (push) Has been cancelled
test / Linux (vim, v8.2.3995) (push) Has been cancelled
test / Windows (nvim, nightly) (push) Has been cancelled
test / Windows (nvim, v0.3.8) (push) Has been cancelled
test / Windows (nvim, v0.4.2) (push) Has been cancelled
test / Windows (nvim, v0.4.3) (push) Has been cancelled
test / Windows (nvim, v0.4.4) (push) Has been cancelled
test / Windows (nvim, v0.5.0) (push) Has been cancelled
test / Windows (nvim, v0.5.1) (push) Has been cancelled
test / Windows (nvim, v0.6.0) (push) Has been cancelled
test / Windows (nvim, v0.6.1) (push) Has been cancelled
test / Windows (nvim, v0.7.0) (push) Has been cancelled
test / Windows (nvim, v0.7.2) (push) Has been cancelled
test / Windows (nvim, v0.8.0) (push) Has been cancelled
test / Windows (nvim, v0.8.1) (push) Has been cancelled
test / Windows (nvim, v0.8.2) (push) Has been cancelled
test / Windows (nvim, v0.8.3) (push) Has been cancelled
test / Windows (nvim, v0.9.0) (push) Has been cancelled
test / Windows (nvim, v0.9.1) (push) Has been cancelled
test / Windows (vim, nightly) (push) Has been cancelled
test / Windows (vim, v7.4.1185) (push) Has been cancelled
test / Windows (vim, v7.4.1689) (push) Has been cancelled
test / Windows (vim, v8.0.0027) (push) Has been cancelled
test / Windows (vim, v8.0.1453) (push) Has been cancelled
test / Windows (vim, v8.1.2269) (push) Has been cancelled
test / Windows (vim, v8.2.2434) (push) Has been cancelled
test / Windows (vim, v8.2.3995) (push) Has been cancelled
docker / docker (push) Has been cancelled
mirror / check (coding) (push) Has been cancelled
mirror / check (gitee) (push) Has been cancelled
mirror / check (gitlab) (push) Has been cancelled
118 lines
4.8 KiB
VimL
118 lines
4.8 KiB
VimL
"=============================================================================
|
|
" regex.vim --- regex parser for vim
|
|
" Copyright (c) 2016-2023 Wang Shidong & Contributors
|
|
" Author: Wang Shidong < wsdjeg@outlook.com >
|
|
" URL: https://spacevim.org
|
|
" License: GPLv3
|
|
"=============================================================================
|
|
let s:self = {}
|
|
|
|
function! s:self.parser(regex, is_perl) abort
|
|
let vim_regex = a:regex
|
|
|
|
" matchadd function needs \ before [%@&]
|
|
let vim_regex = substitute(vim_regex, '\([%@&]\)', '\\\1', 'g')
|
|
|
|
" non-greedy pattern
|
|
" replace from what to what?
|
|
" let vim_regex = substitute(vim_regex, '(?<!\\)\*\?', '{-}', 'g')
|
|
" let vim_regex = substitute(vim_regex, '(?<!\\)\+\?', '{-1,}', 'g')
|
|
" let vim_regex = substitute(vim_regex, '(?<!\\)\?\?', '{-0,1}', 'g')
|
|
" let vim_regex = substitute(vim_regex, '(?<!\\)\{(.*?)\}\?', '{-\1}', 'g')
|
|
|
|
if a:is_perl
|
|
" *+, ++, ?+, {m,n}+ => *, +, ?, {m,n}
|
|
let vim_regex = substitute(vim_regex, '(?<!\\)([*+?}])\+', '\1', 'g')
|
|
" remove (?#....)
|
|
let vim_regex = substitute(vim_regex, '\(\?#.*?\)', '', 'g')
|
|
" (?=atom) => atom\@=
|
|
let vim_regex = substitute(vim_regex, '\(\?=(.+?)\)', '(\1)@=', 'g')
|
|
" (?!atom) => atom\@!
|
|
let vim_regex = substitute(vim_regex, '\(\?!(.+?)\)', '(\1)@!', 'g')
|
|
" (?<=atom) => atom\@<=
|
|
let vim_regex = substitute(vim_regex, '\(\?<=(.+?)\)', '(\1)@<=', 'g')
|
|
" (?<!atom) => atom\@<!
|
|
let vim_regex = substitute(vim_regex, '\(\?<!(.+?)\)', '(\1)@<!', 'g')
|
|
" (?>atom) => atom\@>
|
|
let vim_regex = substitute(vim_regex, '\(\?>(.+?)\)', '(\1)@>', 'g')
|
|
endif
|
|
|
|
" this won't hurt although they are not the same
|
|
let vim_regex = substitute(vim_regex, '\\A', '^', 'g')
|
|
let vim_regex = substitute(vim_regex, '\\z', '$', 'g')
|
|
let vim_regex = substitute(vim_regex, '\\B', '', 'g')
|
|
|
|
" word boundary
|
|
" \bword\b => <word>
|
|
let vim_regex = substitute(vim_regex, '\\b\(\w\+\)\\b', '<\1>', 'g')
|
|
|
|
" right word boundary
|
|
" \bword => \<word
|
|
let vim_regex = substitute(vim_regex, '\\b\(\w\+\)', '<\1', 'g')
|
|
|
|
" left word boundary
|
|
" word\b => word\>
|
|
let vim_regex = substitute(vim_regex, '\(\w\+\)\\b', '\1>', 'g')
|
|
|
|
" case-insensitive
|
|
" (?i)abc => \cabc
|
|
" (?-i)abc => \Cabc
|
|
let vim_regex = substitute(vim_regex, '(?i)', '\\c', 'g')
|
|
let vim_regex = substitute(vim_regex, '(?-i)', '\\C', 'g')
|
|
|
|
" (?P<name>exp) => (exp)
|
|
let vim_regex = substitute(vim_regex, '(?P<\w\+>\([^)]\+\))', '(\1)', 'g')
|
|
|
|
" (?:exp) => %(exp)
|
|
let vim_regex = substitute(vim_regex, '(?:\([^)]\+\))', '%(\1)', 'g')
|
|
|
|
" \a bell (\x07)
|
|
" \f form feed (\x0C)
|
|
" \v vertical tab (\x0B)
|
|
let vim_regex = substitute(vim_regex, '\\a', '%x07', 'g')
|
|
let vim_regex = substitute(vim_regex, '\\f', '%x0C', 'g')
|
|
let vim_regex = substitute(vim_regex, '\\v', '%x0B', 'g')
|
|
|
|
" \123 octal character code (up to three digits) (when enabled)
|
|
" \x7F hex character code (exactly two digits)
|
|
" let vim_regex = substitute(vim_regex, '\\(x[0-9A-Fa-f][0-9A-Fa-f])', '%\1', 'g')
|
|
" \x{10FFFF} any hex character code corresponding to a Unicode code point
|
|
" \u007F hex character code (exactly four digits)
|
|
" \u{7F} any hex character code corresponding to a Unicode code point
|
|
" \U0000007F hex character code (exactly eight digits)
|
|
" \U{7F} any hex character code corresponding to a Unicode code point
|
|
" let vim_regex = substitute(vim_regex, '\\([uU])', '%\1', 'g')
|
|
|
|
let vim_regex = substitute(vim_regex, '\[:ascii:\]', '[\\x00-\\x7F]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:word:\]', '[0-9A-Za-z_]', 'g')
|
|
|
|
let vim_regex = substitute(vim_regex, '\[:alnum:\]', '[^0-9A-Za-z]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:alpha:\]', '[^A-Za-z]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:ascii:\]', '[^\x00-\x7F]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:blank:\]', '[^\t ]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:cntrl:\]', '[^\x00-\x1F\x7F]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:digit:\]', '[^0-9]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:graph:\]', '[^!-~]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:lower:\]', '[^a-z]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:print:\]', '[^ -~]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:punct:\]', '[^!-/:-@\[-`{-~]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:space:\]', '[^\t\n\r ]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:upper:\]', '[^A-Z]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:word:\]', '[^0-9A-Za-z_]', 'g')
|
|
let vim_regex = substitute(vim_regex, '\[:xdigit:\]', '[^0-9A-Fa-f]', 'g')
|
|
|
|
return '\v' . vim_regex
|
|
|
|
endfunction
|
|
|
|
function! SpaceVim#api#vim#regex#get() abort
|
|
|
|
return deepcopy(s:self)
|
|
|
|
endfunction
|
|
|
|
|
|
" NOTE:
|
|
" This idea of self.parser is from:
|
|
" https://github.com/Yggdroot/LeaderF/blob/bc1ed5291191663fa3136f29bb07b8874d1226c3/autoload/leaderf/python/leaderf/rgExpl.py#L300-L380
|