spacevim/bundle/VimRegStyle/autoload/extended_regex.vim
JIe 2bb7059579
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
init
2024-08-21 14:17:26 +08:00

107 lines
2.9 KiB
VimL

" Vim library for short description
" Maintainer: Barry Arthur <barry.arthur@gmail.com>
" Israel Chauca F. <israelchauca@gmail.com>
" Version: 0.1
" Description: Long description.
" Last Change: 2013-02-03
" License: Vim License (see :help license)
" Location: autoload/extended_regex.vim
" Website: https://github.com/Raimondi/extended_regex
"
" See extended_regex.txt for help. This can be accessed by doing:
"
" :helptags ~/.vim/doc
" :help extended_regex
" Vimscript Setup: {{{1
" Allow use of line continuation.
let s:save_cpo = &cpo
set cpo&vim
" load guard
" uncomment after plugin development
" Remove the conditions you do not need, they are there just as an example.
"if exists("g:loaded_lib_extended_regex")
" \ || v:version < 700
" \ || v:version == 703 && !has('patch338')
" \ || &compatible
" let &cpo = s:save_cpo
" finish
"endif
"let g:loaded_lib_extended_regex = 1
" Private Functions: {{{1
" Library Interface: {{{1
function! extended_regex#ExtendedRegex(...)
let erex = {}
let erex.lookup_function = ''
let erex.lookup_dict = {}
func erex.default_lookup(name) dict
return eval(a:name)
endfunc
"TODO: revisit this with eval() solution
func erex.lookup(name) dict
if empty(self.lookup_function)
return call(self.default_lookup, [a:name], self)
else
"TODO: this 'self' dict arg needs to be the object's self...
return call(self.lookup_function, [a:name], self.lookup_dict)
endif
endfunc
func erex.expand_composition_atom(ext_reg) dict
let ext_reg = a:ext_reg
let composition_atom = '\\%{\s*\([^,} \t]\+\)\%(\s*,\s*\(\d\+\)\%(\s*,\s*\(.\{-}\)\)\?\)\?\s*}'
let remaining = match(ext_reg, composition_atom)
while remaining != -1
let [_, name, cnt, sep ;__] = matchlist(ext_reg, composition_atom)
let cnt = cnt ? cnt : 1
let sep = escape(escape(sep, '.*[]$^'), '\\')
let pattern = escape(self.lookup(name), '\\' )
let ext_reg = substitute(ext_reg, composition_atom, join(repeat([pattern], cnt), sep), '')
let remaining = match(ext_reg, composition_atom)
endwhile
return ext_reg
endfunc
func erex.expand(ext_reg) dict
return self.expand_composition_atom(a:ext_reg)
endfunc
func erex.parse_multiline_regex(ext_reg) dict
return substitute(substitute(substitute(a:ext_reg, '#\s\+\S\+', '', 'g'), '\\\@<! ', '', 'g'), '\(\\\\\)\@<=\zs\s\+', '', 'g')
endfunc
" common public API
func erex.register_lookup(callback) dict
let self.lookup_function = a:callback
endfunc
func erex.register_lookup_dict(dict) dict
let self.lookup_dict = a:dict
endfunc
func erex.parse(ext_reg) dict
return self.expand(self.parse_multiline_regex(a:ext_reg))
endfunc
if a:0
call erex.register_lookup(a:1)
if a:0 > 1
call erex.register_lookup_dict(a:2)
endif
endif
return erex
endfunction
" Teardown:{{{1
"reset &cpo back to users setting
let &cpo = s:save_cpo
" vim: set sw=2 sts=2 et fdm=marker: