re.lua 2.2 KB

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