Home Explore Blog CI



neovim

48th chunk of `runtime/doc/lua.txt`
009d2a098d56af70a13dc237845b8f089a5c9ae8db294ad90000000100000fb8
 literally.
    • If the argument is a non-negative number `n`, the result is a pattern
      that matches exactly `n` characters.
    • If the argument is a negative number `-n`, the result is a pattern that
      succeeds only if the input string has less than `n` characters left:
      `lpeg.P(-n)` is equivalent to `-lpeg.P(n)` (see the unary minus
      operation).
    • If the argument is a boolean, the result is a pattern that always
      succeeds or always fails (according to the boolean value), without
      consuming any input.
    • If the argument is a table, it is interpreted as a grammar (see
      Grammars).
    • If the argument is a function, returns a pattern equivalent to a
      match-time capture over the empty string.

    Parameters: ~
      • {value}  (`vim.lpeg.Pattern|string|integer|boolean|table|function`)

    Return: ~
        (`vim.lpeg.Pattern`)

vim.lpeg.R({...})                                               *vim.lpeg.R()*
    Returns a pattern that matches any single character belonging to one of
    the given ranges. Each `range` is a string `xy` of length 2, representing
    all characters with code between the codes of `x` and `y` (both
    inclusive). As an example, the pattern `lpeg.R('09')` matches any digit,
    and `lpeg.R('az', 'AZ')` matches any ASCII letter.

    Example: >lua
        local pattern = lpeg.R('az') ^ 1 * -1
        assert(pattern:match('hello') == 6)
<

    Parameters: ~
      • {...}  (`string`)

    Return: ~
        (`vim.lpeg.Pattern`)

vim.lpeg.S({string})                                            *vim.lpeg.S()*
    Returns a pattern that matches any single character that appears in the
    given string (the `S` stands for Set). As an example, the pattern
    `lpeg.S('+-*/')` matches any arithmetic operator. Note that, if `s` is a
    character (that is, a string of length 1), then `lpeg.P(s)` is equivalent
    to `lpeg.S(s)` which is equivalent to `lpeg.R(s..s)`. Note also that both
    `lpeg.S('')` and `lpeg.R()` are patterns that always fail.

    Parameters: ~
      • {string}  (`string`)

    Return: ~
        (`vim.lpeg.Pattern`)

vim.lpeg.setmaxstack({max})                           *vim.lpeg.setmaxstack()*
    Sets a limit for the size of the backtrack stack used by LPeg to track
    calls and choices. The default limit is `400`. Most well-written patterns
    need little backtrack levels and therefore you seldom need to change this
    limit; before changing it you should try to rewrite your pattern to avoid
    the need for extra space. Nevertheless, a few useful patterns may
    overflow. Also, with recursive grammars, subjects with deep recursion may
    also need larger limits.

    Parameters: ~
      • {max}  (`integer`)

vim.lpeg.type({value})                                       *vim.lpeg.type()*
    Returns the string `"pattern"` if the given value is a pattern, otherwise
    `nil`.

    Parameters: ~
      • {value}  (`vim.lpeg.Pattern|string|integer|boolean|table|function`)

    Return: ~
        (`"pattern"?`)

vim.lpeg.V({v})                                                 *vim.lpeg.V()*
    Creates a non-terminal (a variable) for a grammar. This operation creates
    a non-terminal (a variable) for a grammar. The created non-terminal refers
    to the rule indexed by `v` in the enclosing grammar.

    Example: >lua
        local b = lpeg.P({'(' * ((1 - lpeg.S '()') + lpeg.V(1)) ^ 0 * ')'})
        assert(b:match('((string))') == 11)
        assert(b:match('(') == nil)
<

    Parameters: ~
      • {v}  (`boolean|string|number|function|table|thread|userdata|lightuserdata`)

    Return: ~
        (`vim.lpeg.Pattern`)

vim.lpeg.version()                                        *vim.lpeg.version()*
    Returns a string with the running version of LPeg.

    Return: ~
        (`string`)


==============================================================================
VIM.RE                                                                *vim.re*

The

Title: Lua API: vim.lpeg.R(), vim.lpeg.S(), vim.lpeg.setmaxstack(), vim.lpeg.type(), vim.lpeg.V() and vim.lpeg.version()
Summary
This section describes several functions within the `vim.lpeg` module. `vim.lpeg.R()` creates a pattern that matches any character within specified ranges. `vim.lpeg.S()` creates a pattern that matches any character in a given string. `vim.lpeg.setmaxstack()` sets the limit for the backtrack stack size. `vim.lpeg.type()` returns "pattern" if the value is a pattern. `vim.lpeg.V()` creates a non-terminal for a grammar, referencing a rule indexed by `v`. Finally, `vim.lpeg.version()` returns the LPeg version string.