docs(lpeg): merge upstream changes

This commit is contained in:
Maria José Solano 2024-07-15 12:55:57 -07:00 committed by Lewis Russell
parent 3c803483ac
commit 8703e7bd12
2 changed files with 43 additions and 37 deletions

View File

@ -3090,7 +3090,7 @@ In addition, its regex-like interface is available as |vim.re|
Pattern:match({subject}, {init}) *Pattern:match()* Pattern:match({subject}, {init}, {...}) *Pattern:match()*
Matches the given `pattern` against the `subject` string. If the match Matches the given `pattern` against the `subject` string. If the match
succeeds, returns the index in the subject of the first character after succeeds, returns the index in the subject of the first character after
the match, or the captured values (if the pattern captured any value). An the match, or the captured values (if the pattern captured any value). An
@ -3113,9 +3113,10 @@ Pattern:match({subject}, {init}) *Pattern:match()*
Parameters: ~ Parameters: ~
• {subject} (`string`) • {subject} (`string`)
• {init} (`integer?`) • {init} (`integer?`)
• {...} (`any`)
Return: ~ Return: ~
(`integer|vim.lpeg.Capture?`) (`any`) ...
vim.lpeg.B({pattern}) *vim.lpeg.B()* vim.lpeg.B({pattern}) *vim.lpeg.B()*
Returns a pattern that matches only if the input string at the current Returns a pattern that matches only if the input string at the current
@ -3125,7 +3126,7 @@ vim.lpeg.B({pattern}) *vim.lpeg.B()*
or failure. or failure.
Parameters: ~ Parameters: ~
• {pattern} (`vim.lpeg.Pattern`) • {pattern} (`vim.lpeg.Pattern|string|integer|boolean|table`)
Return: ~ Return: ~
(`vim.lpeg.Pattern`) (`vim.lpeg.Pattern`)
@ -3149,7 +3150,7 @@ vim.lpeg.C({patt}) *vim.lpeg.C()*
< <
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
Return: ~ Return: ~
(`vim.lpeg.Capture`) (`vim.lpeg.Capture`)
@ -3200,11 +3201,11 @@ vim.lpeg.Cf({patt}, {func}) *vim.lpeg.Cf()*
This capture assumes that `patt` should produce at least one capture with This capture assumes that `patt` should produce at least one capture with
at least one value (of any type), which becomes the initial value of an at least one value (of any type), which becomes the initial value of an
accumulator. (If you need a specific initial value, you may prefix a accumulator. (If you need a specific initial value, you may prefix a
constant captureto `patt`.) For each subsequent capture, LPeg calls `func` constant capture to `patt`.) For each subsequent capture, LPeg calls
with this accumulator as the first argument and all values produced by the `func` with this accumulator as the first argument and all values produced
capture as extra arguments; the first result from this call becomes the by the capture as extra arguments; the first result from this call becomes
new value for the accumulator. The final value of the accumulator becomes the new value for the accumulator. The final value of the accumulator
the captured value. becomes the captured value.
Example: >lua Example: >lua
local number = lpeg.R('09') ^ 1 / tonumber local number = lpeg.R('09') ^ 1 / tonumber
@ -3215,7 +3216,7 @@ vim.lpeg.Cf({patt}, {func}) *vim.lpeg.Cf()*
< <
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
• {func} (`fun(acc, newvalue)`) • {func} (`fun(acc, newvalue)`)
Return: ~ Return: ~
@ -3227,7 +3228,7 @@ vim.lpeg.Cg({patt}, {name}) *vim.lpeg.Cg()*
with the given name (which can be any non-nil Lua value). with the given name (which can be any non-nil Lua value).
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
• {name} (`string?`) • {name} (`string?`)
Return: ~ Return: ~
@ -3250,8 +3251,9 @@ vim.lpeg.Cmt({patt}, {fn}) *vim.lpeg.Cmt()*
function become the values produced by the capture. function become the values produced by the capture.
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
• {fn} (`function`) • {fn} (`fun(s: string, i: integer, ...: any)`) (position:
boolean|integer, ...: any)
Return: ~ Return: ~
(`vim.lpeg.Capture`) (`vim.lpeg.Capture`)
@ -3290,7 +3292,7 @@ vim.lpeg.Cs({patt}) *vim.lpeg.Cs()*
< <
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
Return: ~ Return: ~
(`vim.lpeg.Capture`) (`vim.lpeg.Capture`)
@ -3303,7 +3305,7 @@ vim.lpeg.Ct({patt}) *vim.lpeg.Ct()*
the group name as its key. The captured value is only the table. the group name as its key. The captured value is only the table.
Parameters: ~ Parameters: ~
• {patt} (`vim.lpeg.Pattern|''`) • {patt} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
Return: ~ Return: ~
(`vim.lpeg.Capture`) (`vim.lpeg.Capture`)
@ -3338,7 +3340,7 @@ vim.lpeg.locale({tab}) *vim.lpeg.locale()*
Return: ~ Return: ~
(`vim.lpeg.Locale`) (`vim.lpeg.Locale`)
vim.lpeg.match({pattern}, {subject}, {init}) *vim.lpeg.match()* vim.lpeg.match({pattern}, {subject}, {init}, {...}) *vim.lpeg.match()*
Matches the given `pattern` against the `subject` string. If the match Matches the given `pattern` against the `subject` string. If the match
succeeds, returns the index in the subject of the first character after succeeds, returns the index in the subject of the first character after
the match, or the captured values (if the pattern captured any value). An the match, or the captured values (if the pattern captured any value). An
@ -3359,12 +3361,13 @@ vim.lpeg.match({pattern}, {subject}, {init}) *vim.lpeg.match()*
< <
Parameters: ~ Parameters: ~
• {pattern} (`vim.lpeg.Pattern`) • {pattern} (`vim.lpeg.Pattern|string|integer|boolean|table|function`)
• {subject} (`string`) • {subject} (`string`)
• {init} (`integer?`) • {init} (`integer?`)
• {...} (`any`)
Return: ~ Return: ~
(`integer|vim.lpeg.Capture?`) (`any`) ...
vim.lpeg.P({value}) *vim.lpeg.P()* vim.lpeg.P({value}) *vim.lpeg.P()*
Converts the given value into a proper pattern. The following rules are Converts the given value into a proper pattern. The following rules are
@ -3458,7 +3461,7 @@ vim.lpeg.V({v}) *vim.lpeg.V()*
< <
Parameters: ~ Parameters: ~
• {v} (`string|integer`) • {v} (`boolean|string|number|function|table|thread|userdata|lightuserdata`)
Return: ~ Return: ~
(`vim.lpeg.Pattern`) (`vim.lpeg.Pattern`)

View File

@ -2,7 +2,7 @@
error('Cannot require a meta file') error('Cannot require a meta file')
-- These types were taken from https://github.com/LuaCATS/lpeg -- These types were taken from https://github.com/LuaCATS/lpeg
-- (based on revision 82c6a8fc676bbc20722026afd952668f3919b11d) -- (based on revision 33f4ff5343a64cf613a0634d70092fbc2b64291b)
-- with types being renamed to include the vim namespace and with some descriptions made less verbose. -- with types being renamed to include the vim namespace and with some descriptions made less verbose.
--- @brief <pre>help --- @brief <pre>help
@ -22,16 +22,17 @@ vim.lpeg = {}
--- @nodoc --- @nodoc
--- @class vim.lpeg.Pattern --- @class vim.lpeg.Pattern
--- @operator len: vim.lpeg.Pattern
--- @operator unm: vim.lpeg.Pattern --- @operator unm: vim.lpeg.Pattern
--- @operator add(vim.lpeg.Pattern): vim.lpeg.Pattern --- @operator add(vim.lpeg.Pattern): vim.lpeg.Pattern
--- @operator sub(vim.lpeg.Pattern): vim.lpeg.Pattern --- @operator sub(vim.lpeg.Pattern): vim.lpeg.Pattern
--- @operator mul(vim.lpeg.Pattern): vim.lpeg.Pattern --- @operator mul(vim.lpeg.Pattern): vim.lpeg.Pattern
--- @operator mul(vim.lpeg.Capture): vim.lpeg.Pattern --- @operator mul(vim.lpeg.Capture): vim.lpeg.Pattern
--- @operator div(string): vim.lpeg.Capture --- @operator div(string): vim.lpeg.Capture
--- @operator div(number): vim.lpeg.Capture --- @operator div(integer): vim.lpeg.Capture
--- @operator div(table): vim.lpeg.Capture --- @operator div(table): vim.lpeg.Capture
--- @operator div(function): vim.lpeg.Capture --- @operator div(function): vim.lpeg.Capture
--- @operator pow(number): vim.lpeg.Pattern --- @operator pow(integer): vim.lpeg.Pattern
--- @operator mod(function): vim.lpeg.Capture --- @operator mod(function): vim.lpeg.Capture
local Pattern = {} local Pattern = {}
@ -55,11 +56,12 @@ local Pattern = {}
--- assert(pattern:match('1 hello') == nil) --- assert(pattern:match('1 hello') == nil)
--- ``` --- ```
--- ---
--- @param pattern vim.lpeg.Pattern --- @param pattern vim.lpeg.Pattern|string|integer|boolean|table|function
--- @param subject string --- @param subject string
--- @param init? integer --- @param init? integer
--- @return integer|vim.lpeg.Capture|nil --- @param ... any
function vim.lpeg.match(pattern, subject, init) end --- @return any ...
function vim.lpeg.match(pattern, subject, init, ...) end
--- Matches the given `pattern` against the `subject` string. If the match succeeds, returns the --- Matches the given `pattern` against the `subject` string. If the match succeeds, returns the
--- index in the subject of the first character after the match, or the captured values (if the --- index in the subject of the first character after the match, or the captured values (if the
@ -81,8 +83,9 @@ function vim.lpeg.match(pattern, subject, init) end
--- ---
--- @param subject string --- @param subject string
--- @param init? integer --- @param init? integer
--- @return integer|vim.lpeg.Capture|nil --- @param ... any
function Pattern:match(subject, init) end --- @return any ...
function Pattern:match(subject, init, ...) end
--- Returns the string `"pattern"` if the given value is a pattern, otherwise `nil`. --- Returns the string `"pattern"` if the given value is a pattern, otherwise `nil`.
--- ---
@ -123,7 +126,7 @@ function vim.lpeg.P(value) end
--- Pattern `patt` must match only strings with some fixed length, and it cannot contain captures. --- Pattern `patt` must match only strings with some fixed length, and it cannot contain captures.
--- Like the `and` predicate, this pattern never consumes any input, independently of success or failure. --- Like the `and` predicate, this pattern never consumes any input, independently of success or failure.
--- ---
--- @param pattern vim.lpeg.Pattern --- @param pattern vim.lpeg.Pattern|string|integer|boolean|table
--- @return vim.lpeg.Pattern --- @return vim.lpeg.Pattern
function vim.lpeg.B(pattern) end function vim.lpeg.B(pattern) end
@ -163,7 +166,7 @@ function vim.lpeg.S(string) end
--- assert(b:match('(') == nil) --- assert(b:match('(') == nil)
--- ``` --- ```
--- ---
--- @param v string|integer --- @param v boolean|string|number|function|table|thread|userdata|lightuserdata
--- @return vim.lpeg.Pattern --- @return vim.lpeg.Pattern
function vim.lpeg.V(v) end function vim.lpeg.V(v) end
@ -227,7 +230,7 @@ function vim.lpeg.locale(tab) end
--- assert(c == 'c') --- assert(c == 'c')
--- ``` --- ```
--- ---
--- @param patt vim.lpeg.Pattern --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.C(patt) end function vim.lpeg.C(patt) end
@ -258,7 +261,7 @@ function vim.lpeg.Cc(...) end
--- `func(...func(func(C1, C2), C3)...,Cn)`, that is, it will fold (or accumulate, or reduce) the captures from --- `func(...func(func(C1, C2), C3)...,Cn)`, that is, it will fold (or accumulate, or reduce) the captures from
--- `patt` using function `func`. This capture assumes that `patt` should produce at least one capture with at --- `patt` using function `func`. This capture assumes that `patt` should produce at least one capture with at
--- least one value (of any type), which becomes the initial value of an accumulator. (If you need a specific --- least one value (of any type), which becomes the initial value of an accumulator. (If you need a specific
--- initial value, you may prefix a constant captureto `patt`.) For each subsequent capture, LPeg calls `func` --- initial value, you may prefix a constant capture to `patt`.) For each subsequent capture, LPeg calls `func`
--- with this accumulator as the first argument and all values produced by the capture as extra arguments; --- with this accumulator as the first argument and all values produced by the capture as extra arguments;
--- the first result from this call becomes the new value for the accumulator. The final value of the accumulator --- the first result from this call becomes the new value for the accumulator. The final value of the accumulator
--- becomes the captured value. --- becomes the captured value.
@ -273,7 +276,7 @@ function vim.lpeg.Cc(...) end
--- assert(sum:match('10,30,43') == 83) --- assert(sum:match('10,30,43') == 83)
--- ``` --- ```
--- ---
--- @param patt vim.lpeg.Pattern --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @param func fun(acc, newvalue) --- @param func fun(acc, newvalue)
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.Cf(patt, func) end function vim.lpeg.Cf(patt, func) end
@ -282,7 +285,7 @@ function vim.lpeg.Cf(patt, func) end
--- The group may be anonymous (if no name is given) or named with the given name (which --- The group may be anonymous (if no name is given) or named with the given name (which
--- can be any non-nil Lua value). --- can be any non-nil Lua value).
--- ---
--- @param patt vim.lpeg.Pattern --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @param name? string --- @param name? string
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.Cg(patt, name) end function vim.lpeg.Cg(patt, name) end
@ -320,7 +323,7 @@ function vim.lpeg.Cp() end
--- assert(gsub('Hello, xxx!', 'xxx', 'World') == 'Hello, World!') --- assert(gsub('Hello, xxx!', 'xxx', 'World') == 'Hello, World!')
--- ``` --- ```
--- ---
--- @param patt vim.lpeg.Pattern --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.Cs(patt) end function vim.lpeg.Cs(patt) end
@ -329,7 +332,7 @@ function vim.lpeg.Cs(patt) end
--- Moreover, for each named capture group created by `patt`, the first value of the group is put into --- Moreover, for each named capture group created by `patt`, the first value of the group is put into
--- the table with the group name as its key. The captured value is only the table. --- the table with the group name as its key. The captured value is only the table.
--- ---
--- @param patt vim.lpeg.Pattern|'' --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.Ct(patt) end function vim.lpeg.Ct(patt) end
@ -343,7 +346,7 @@ function vim.lpeg.Ct(patt) end
--- (so, to return true is equivalent to return `i`). If the call returns `false`, `nil`, or no value, the match fails. --- (so, to return true is equivalent to return `i`). If the call returns `false`, `nil`, or no value, the match fails.
--- Any extra values returned by the function become the values produced by the capture. --- Any extra values returned by the function become the values produced by the capture.
--- ---
--- @param patt vim.lpeg.Pattern --- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
--- @param fn function --- @param fn fun(s: string, i: integer, ...: any): (position: boolean|integer, ...: any)
--- @return vim.lpeg.Capture --- @return vim.lpeg.Capture
function vim.lpeg.Cmt(patt, fn) end function vim.lpeg.Cmt(patt, fn) end