re.lua (2270B)
1 --- @meta 2 error('Cannot require a meta file') 3 4 -- Documentations and Lua types for vim.re (vendored re.lua, lpeg-1.1.0) 5 -- https://www.inf.puc-rio.br/~roberto/lpeg/re.html 6 -- 7 -- Copyright © 2007-2023 Lua.org, PUC-Rio. 8 -- See 'lpeg.html' for license 9 10 --- @brief 11 --- The `vim.re` module provides a conventional regex-like syntax for pattern usage within LPeg 12 --- |vim.lpeg|. (Unrelated to |vim.regex| which provides Vim |regexp| from Lua.) 13 --- 14 --- See https://www.inf.puc-rio.br/~roberto/lpeg/re.html for the original documentation including 15 --- regex syntax and examples. 16 17 --- Compiles the given {string} and returns an equivalent LPeg pattern. The given string may define 18 --- either an expression or a grammar. The optional {defs} table provides extra Lua values to be used 19 --- by the pattern. 20 --- @param string string 21 --- @param defs? table 22 --- @return vim.lpeg.Pattern 23 function vim.re.compile(string, defs) end 24 25 --- Searches the given {pattern} in the given {subject}. If it finds a match, returns the index 26 --- where this occurrence starts and the index where it ends. Otherwise, returns nil. 27 --- 28 --- An optional numeric argument {init} makes the search starts at that position in the subject 29 --- string. As usual in Lua libraries, a negative value counts from the end. 30 --- @param subject string 31 --- @param pattern vim.lpeg.Pattern|string 32 --- @param init? integer 33 --- @return integer|nil : the index where the occurrence starts, nil if no match 34 --- @return integer|nil : the index where the occurrence ends, nil if no match 35 function vim.re.find(subject, pattern, init) end 36 37 --- Does a global substitution, replacing all occurrences of {pattern} in the given {subject} by 38 --- {replacement}. 39 --- @param subject string 40 --- @param pattern vim.lpeg.Pattern|string 41 --- @param replacement string 42 --- @return string 43 function vim.re.gsub(subject, pattern, replacement) end 44 45 --- Matches the given {pattern} against the given {subject}, returning all captures. 46 --- @param subject string 47 --- @param pattern vim.lpeg.Pattern|string 48 --- @param init? integer 49 --- @return integer|vim.lpeg.Capture|nil 50 --- @see vim.lpeg.match() 51 function vim.re.match(subject, pattern, init) end 52 53 --- Updates the pre-defined character classes to the current locale. 54 function vim.re.updatelocale() end