robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. Keyesfix(lua): not obvious which _meta/ files are generated #3903565b40e69ac

master
15.4 KiB353 linesraw
1--- @meta
2-- This file is NOT generated, edit it directly.
3error('Cannot require a meta file')
4
5-- These types were taken from https://github.com/LuaCATS/lpeg
6-- (based on revision 33f4ff5343a64cf613a0634d70092fbc2b64291b)
7-- with types being renamed to include the vim namespace and with some descriptions made less verbose.
8
9--- @brief <pre>help
10--- LPeg is a pattern-matching library for Lua, based on Parsing Expression
11--- Grammars (PEGs). https://bford.info/packrat/
12---
13---                                                  *lua-lpeg* *vim.lpeg.Pattern*
14--- The LPeg library for parsing expression grammars is included as `vim.lpeg`
15--- (https://www.inf.puc-rio.br/~roberto/lpeg/).
16---
17--- In addition, its regex-like interface is available as |vim.re|
18--- (https://www.inf.puc-rio.br/~roberto/lpeg/re.html).
19---
20--- </pre>
21
22vim.lpeg = {}
23
24--- @nodoc
25--- @class vim.lpeg.Pattern
26--- @operator len: vim.lpeg.Pattern
27--- @operator unm: vim.lpeg.Pattern
28--- @operator add(vim.lpeg.Pattern): vim.lpeg.Pattern
29--- @operator sub(vim.lpeg.Pattern): vim.lpeg.Pattern
30--- @operator mul(vim.lpeg.Pattern): vim.lpeg.Pattern
31--- @operator mul(vim.lpeg.Capture): vim.lpeg.Pattern
32--- @operator div(string): vim.lpeg.Capture
33--- @operator div(integer): vim.lpeg.Capture
34--- @operator div(table): vim.lpeg.Capture
35--- @operator div(function): vim.lpeg.Capture
36--- @operator pow(integer): vim.lpeg.Pattern
37--- @operator mod(function): vim.lpeg.Capture
38local Pattern = {}
39
40--- @alias vim.lpeg.Capture vim.lpeg.Pattern
41
42--- Matches the given `pattern` against the `subject` string. If the match succeeds, returns the index in the
43--- subject of the first character after the match, or the captured values (if the pattern captured any value).
44--- An optional numeric argument `init` makes the match start at that position in the subject string. As usual
45--- in Lua libraries, a negative value counts from the end. Unlike typical pattern-matching functions, `match`
46--- works only in anchored mode; that is, it tries to match the pattern with a prefix of the given subject
47--- string (at position `init`), not with an arbitrary substring of the subject. So, if we want to find a
48--- pattern anywhere in a string, we must either write a loop in Lua or write a pattern that
49--- matches anywhere.
50---
51--- Example:
52---
53--- ```lua
54--- local pattern = lpeg.R('az') ^ 1 * -1
55--- assert(pattern:match('hello') == 6)
56--- assert(lpeg.match(pattern, 'hello') == 6)
57--- assert(pattern:match('1 hello') == nil)
58--- ```
59---
60--- @param pattern vim.lpeg.Pattern|string|integer|boolean|table|function
61--- @param subject string
62--- @param init? integer
63--- @param ... any
64--- @return any ...
65function vim.lpeg.match(pattern, subject, init, ...) end
66
67--- Matches the given `pattern` against the `subject` string. If the match succeeds, returns the
68--- index in the subject of the first character after the match, or the captured values (if the
69--- pattern captured any value). An optional numeric argument `init` makes the match start at
70--- that position in the subject string. As usual in Lua libraries, a negative value counts from the end.
71--- Unlike typical pattern-matching functions, `match` works only in anchored mode; that is, it tries
72--- to match the pattern with a prefix of the given subject string (at position `init`), not with
73--- an arbitrary substring of the subject. So, if we want to find a pattern anywhere in a string,
74--- we must either write a loop in Lua or write a pattern that matches anywhere.
75---
76--- Example:
77---
78--- ```lua
79--- local pattern = lpeg.R('az') ^ 1 * -1
80--- assert(pattern:match('hello') == 6)
81--- assert(lpeg.match(pattern, 'hello') == 6)
82--- assert(pattern:match('1 hello') == nil)
83--- ```
84---
85--- @param subject string
86--- @param init? integer
87--- @param ... any
88--- @return any ...
89function Pattern:match(subject, init, ...) end
90
91--- Returns the string `"pattern"` if the given value is a pattern, otherwise `nil`.
92---
93--- @param value vim.lpeg.Pattern|string|integer|boolean|table|function
94--- @return "pattern"|nil
95function vim.lpeg.type(value) end
96
97--- Returns a string with the running version of LPeg.
98--- @return string
99function vim.lpeg.version() end
100
101--- Sets a limit for the size of the backtrack stack used by LPeg to track calls and choices.
102--- The default limit is `400`. Most well-written patterns need little backtrack levels and
103--- therefore you seldom need to change this limit; before changing it you should try to rewrite
104--- your pattern to avoid the need for extra space. Nevertheless, a few useful patterns may overflow.
105--- Also, with recursive grammars, subjects with deep recursion may also need larger limits.
106---
107--- @param max integer
108function vim.lpeg.setmaxstack(max) end
109
110--- Converts the given value into a proper pattern. The following rules are applied:
111--- * If the argument is a pattern, it is returned unmodified.
112--- * If the argument is a string, it is translated to a pattern that matches the string literally.
113--- * If the argument is a non-negative number `n`, the result is a pattern that matches exactly `n` characters.
114--- * If the argument is a negative number `-n`, the result is a pattern that succeeds only if
115--- the input string has less than `n` characters left: `lpeg.P(-n)` is equivalent to `-lpeg.P(n)`
116--- (see the unary minus operation).
117--- * If the argument is a boolean, the result is a pattern that always succeeds or always fails
118--- (according to the boolean value), without consuming any input.
119--- * If the argument is a table, it is interpreted as a grammar (see Grammars).
120--- * If the argument is a function, returns a pattern equivalent to a match-time capture over the empty string.
121---
122--- @param value vim.lpeg.Pattern|string|integer|boolean|table|function
123--- @return vim.lpeg.Pattern
124function vim.lpeg.P(value) end
125
126--- Returns a pattern that matches only if the input string at the current position is preceded by `patt`.
127--- Pattern `patt` must match only strings with some fixed length, and it cannot contain captures.
128--- Like the `and` predicate, this pattern never consumes any input, independently of success or failure.
129---
130--- @param pattern vim.lpeg.Pattern|string|integer|boolean|table
131--- @return vim.lpeg.Pattern
132function vim.lpeg.B(pattern) end
133
134--- Returns a pattern that matches any single character belonging to one of the given ranges.
135--- Each `range` is a string `xy` of length 2, representing all characters with code between the codes of
136--- `x` and `y` (both inclusive). As an example, the pattern `lpeg.R('09')` matches any digit, and
137--- `lpeg.R('az', 'AZ')` matches any ASCII letter.
138---
139--- Example:
140---
141--- ```lua
142--- local pattern = lpeg.R('az') ^ 1 * -1
143--- assert(pattern:match('hello') == 6)
144--- ```
145---
146--- @param ... string
147--- @return vim.lpeg.Pattern
148function vim.lpeg.R(...) end
149
150--- Returns a pattern that matches any single character that appears in the given string (the `S` stands for Set).
151--- As an example, the pattern `lpeg.S('+-*/')` matches any arithmetic operator. Note that, if `s` is a character
152--- (that is, a string of length 1), then `lpeg.P(s)` is equivalent to `lpeg.S(s)` which is equivalent to
153--- `lpeg.R(s..s)`. Note also that both `lpeg.S('')` and `lpeg.R()` are patterns that always fail.
154---
155--- @param string string
156--- @return vim.lpeg.Pattern
157function vim.lpeg.S(string) end
158
159--- Creates a non-terminal (a variable) for a grammar. This operation creates a non-terminal (a variable)
160--- for a grammar. The created non-terminal refers to the rule indexed by `v` in the enclosing grammar.
161---
162--- Example:
163---
164--- ```lua
165--- local b = lpeg.P({'(' * ((1 - lpeg.S '()') + lpeg.V(1)) ^ 0 * ')'})
166--- assert(b:match('((string))') == 11)
167--- assert(b:match('(') == nil)
168--- ```
169---
170--- @param v boolean|string|number|function|table|thread|userdata|lightuserdata 
171--- @return vim.lpeg.Pattern
172function vim.lpeg.V(v) end
173
174--- @nodoc
175--- @class vim.lpeg.Locale
176--- @field alnum userdata
177--- @field alpha userdata
178--- @field cntrl userdata
179--- @field digit userdata
180--- @field graph userdata
181--- @field lower userdata
182--- @field print userdata
183--- @field punct userdata
184--- @field space userdata
185--- @field upper userdata
186--- @field xdigit userdata
187
188--- Returns a table with patterns for matching some character classes according to the current locale.
189--- The table has fields named `alnum`, `alpha`, `cntrl`, `digit`, `graph`, `lower`, `print`, `punct`,
190--- `space`, `upper`, and `xdigit`, each one containing a correspondent pattern. Each pattern matches
191--- any single character that belongs to its class.
192--- If called with an argument `table`, then it creates those fields inside the given table and returns
193--- that table.
194---
195--- Example:
196---
197--- ```lua
198--- lpeg.locale(lpeg)
199--- local space = lpeg.space ^ 0
200--- local name = lpeg.C(lpeg.alpha ^ 1) * space
201--- local sep = lpeg.S(',;') * space
202--- local pair = lpeg.Cg(name * '=' * space * name) * sep ^ -1
203--- local list = lpeg.Cf(lpeg.Ct('') * pair ^ 0, rawset)
204--- local t = list:match('a=b, c = hi; next = pi')
205--- assert(t.a == 'b')
206--- assert(t.c == 'hi')
207--- assert(t.next == 'pi')
208--- local locale = lpeg.locale()
209--- assert(type(locale.digit) == 'userdata')
210--- ```
211---
212--- @param tab? table
213--- @return vim.lpeg.Locale
214function vim.lpeg.locale(tab) end
215
216--- Creates a simple capture, which captures the substring of the subject that matches `patt`.
217--- The captured value is a string. If `patt` has other captures, their values are returned after this one.
218---
219--- Example:
220---
221--- ```lua
222--- local function split (s, sep)
223---   sep = lpeg.P(sep)
224---   local elem = lpeg.C((1 - sep) ^ 0)
225---   local p = elem * (sep * elem) ^ 0
226---   return lpeg.match(p, s)
227--- end
228--- local a, b, c = split('a,b,c', ',')
229--- assert(a == 'a')
230--- assert(b == 'b')
231--- assert(c == 'c')
232--- ```
233---
234--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
235--- @return vim.lpeg.Capture
236function vim.lpeg.C(patt) end
237
238--- Creates an argument capture. This pattern matches the empty string and produces the value given as the
239--- nth extra argument given in the call to `lpeg.match`.
240--- @param n integer
241--- @return vim.lpeg.Capture
242function vim.lpeg.Carg(n) end
243
244--- Creates a back capture. This pattern matches the empty string and produces the values produced by the most recent
245--- group capture named `name` (where `name` can be any Lua value). Most recent means the last complete outermost
246--- group capture with the given name. A Complete capture means that the entire pattern corresponding to the capture
247--- has matched. An Outermost capture means that the capture is not inside another complete capture.
248--- In the same way that LPeg does not specify when it evaluates captures, it does not specify whether it reuses
249--- values previously produced by the group or re-evaluates them.
250---
251--- @param name any
252--- @return vim.lpeg.Capture
253function vim.lpeg.Cb(name) end
254
255--- Creates a constant capture. This pattern matches the empty string and produces all given values as its captured values.
256---
257--- @param ... any
258--- @return vim.lpeg.Capture
259function vim.lpeg.Cc(...) end
260
261--- Creates a fold capture. If `patt` produces a list of captures C1 C2 ... Cn, this capture will produce the value
262--- `func(...func(func(C1, C2), C3)...,Cn)`, that is, it will fold (or accumulate, or reduce) the captures from
263--- `patt` using function `func`. This capture assumes that `patt` should produce at least one capture with at
264--- least one value (of any type), which becomes the initial value of an accumulator. (If you need a specific
265--- initial value, you may prefix a constant capture to `patt`.) For each subsequent capture, LPeg calls `func`
266--- with this accumulator as the first argument and all values produced by the capture as extra arguments;
267--- the first result from this call becomes the new value for the accumulator. The final value of the accumulator
268--- becomes the captured value.
269---
270--- Example:
271---
272--- ```lua
273--- local number = lpeg.R('09') ^ 1 / tonumber
274--- local list = number * (',' * number) ^ 0
275--- local function add(acc, newvalue) return acc + newvalue end
276--- local sum = lpeg.Cf(list, add)
277--- assert(sum:match('10,30,43') == 83)
278--- ```
279---
280--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
281--- @param func fun(acc, newvalue)
282--- @return vim.lpeg.Capture
283function vim.lpeg.Cf(patt, func) end
284
285--- Creates a group capture. It groups all values returned by `patt` into a single capture.
286--- The group may be anonymous (if no name is given) or named with the given name (which
287--- can be any non-nil Lua value).
288---
289--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
290--- @param name? string
291--- @return vim.lpeg.Capture
292function vim.lpeg.Cg(patt, name) end
293
294--- Creates a position capture. It matches the empty string and captures the position in the
295--- subject where the match occurs. The captured value is a number.
296---
297--- Example:
298---
299--- ```lua
300--- local I = lpeg.Cp()
301--- local function anywhere(p) return lpeg.P({I * p * I + 1 * lpeg.V(1)}) end
302--- local match_start, match_end = anywhere('world'):match('hello world!')
303--- assert(match_start == 7)
304--- assert(match_end == 12)
305--- ```
306---
307--- @return vim.lpeg.Capture
308function vim.lpeg.Cp() end
309
310--- Creates a substitution capture. This function creates a substitution capture, which
311--- captures the substring of the subject that matches `patt`, with substitutions.
312--- For any capture inside `patt` with a value, the substring that matched the capture
313--- is replaced by the capture value (which should be a string). The final captured
314--- value is the string resulting from all replacements.
315---
316--- Example:
317---
318--- ```lua
319--- local function gsub (s, patt, repl)
320---   patt = lpeg.P(patt)
321---   patt = lpeg.Cs((patt / repl + 1) ^ 0)
322---   return lpeg.match(patt, s)
323--- end
324--- assert(gsub('Hello, xxx!', 'xxx', 'World') == 'Hello, World!')
325--- ```
326---
327--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
328--- @return vim.lpeg.Capture
329function vim.lpeg.Cs(patt) end
330
331--- Creates a table capture. This capture returns a table with all values from all anonymous captures
332--- made by `patt` inside this table in successive integer keys, starting at 1.
333--- Moreover, for each named capture group created by `patt`, the first value of the group is put into
334--- the table with the group name as its key. The captured value is only the table.
335---
336--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
337--- @return vim.lpeg.Capture
338function vim.lpeg.Ct(patt) end
339
340--- Creates a match-time capture. Unlike all other captures, this one is evaluated immediately when a match occurs
341--- (even if it is part of a larger pattern that fails later). It forces the immediate evaluation of all its nested captures
342--- and then calls `function`. The given function gets as arguments the entire subject, the current position
343--- (after the match of `patt`), plus any capture values produced by `patt`. The first value returned by `function`
344--- defines how the match happens. If the call returns a number, the match succeeds and the returned number
345--- becomes the new current position. (Assuming a subject sand current position `i`, the returned number must be
346--- in the range `[i, len(s) + 1]`.) If the call returns `true`, the match succeeds without consuming any input
347--- (so, to return true is equivalent to return `i`). If the call returns `false`, `nil`, or no value, the match fails.
348--- Any extra values returned by the function become the values produced by the capture.
349---
350--- @param patt vim.lpeg.Pattern|string|integer|boolean|table|function
351--- @param fn fun(s: string, i: integer, ...: any): (position: boolean|integer, ...: any)
352--- @return vim.lpeg.Capture
353function vim.lpeg.Cmt(patt, fn) end