Skip to content

global lpeg


methods


lpeg.UP


function lpeg.UP()

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.UR


function lpeg.UR()

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.US


function lpeg.US()

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.afterprefix


function lpeg.afterprefix()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.anywhere


function lpeg.anywhere()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.append


function lpeg.append()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.balancer


function lpeg.balancer()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.beforesuffix


function lpeg.beforesuffix()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.containsws


function lpeg.containsws()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.counter


function lpeg.counter()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.endstripper


function lpeg.endstripper()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.finder


function lpeg.finder()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.frontstripper


function lpeg.frontstripper()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.instringchecker


function lpeg.instringchecker()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.is_lpeg


function lpeg.is_lpeg()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.oneof


function lpeg.oneof()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.pcode


function lpeg.pcode()

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.print


function lpeg.print()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.ptree


function lpeg.ptree()

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.setutfcasers


function lpeg.setutfcasers()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.splitter


function lpeg.splitter()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.splitat


function lpeg.splitat(
  delimiter: string,
  single: boolean?
) ->  Pattern

Return a pattern that produces a list of substrings delimited by delimiter (which can be a pattern or a string).

The optional boolean single determines whether the string should be split only at the first match.

Example:

local str = [[
Number twenty-three. The shin.
Number twenty-four. Reginald Maudling's shin.
Number twenty-five. The brain.
Number twenty-six. Magaret Thatcher's brain.
Number twenty-seven. More naughty bits.
]]

local t = { lpeg.splitat("Number", false):match(str) }
for n, element in pairs(t) do
  element = element == "" and element .. "\n" or element
  io.write(n .. ": " .. element)
end

Reference:

lpeg.firstofsplit


function lpeg.firstofsplit(separator: string) ->  Pattern

Return a pattern that matches the substring until the first occurrence of separator

Example:

local str =
  "menu = spam, spam, spam, spam, spam, baked beans, spam, spam and spam"
print(lpeg.firstofsplit(" = "):match(str))

Reference:

lpeg.secondofsplit


function lpeg.secondofsplit(separator: string) ->  Pattern

Match the whole rest after that regardless of any further occurrences of separator.

Example:

local str =
  "menu = spam, spam, spam, spam, spam, baked beans, spam, spam and spam"
print(lpeg.secondofsplit(" = "):match(str))

Reference:

lpeg.split


function lpeg.split()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.checkedsplit


function lpeg.checkedsplit()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.stripper


function lpeg.stripper(pattern: (string|Pattern)) ->  Pattern

Return a pattern that removes either, if the argument is a string, all occurrences of every character of that string or, if the argument is a pattern, all occurrences of that pattern.

Example:

local str =
  "A dromedary has one hump and a camel has a refreshment car, buffet, and ticket collector."
print(lpeg.stripper("aeiou"):match(str))
print(lpeg.stripper(lpeg.P("camel ")):match(str))

Reference:

@see lpeg.keeper

lpeg.keeper


function lpeg.keeper(pattern: (string|Pattern)) ->  Pattern

Remove anything but the string or pattern respectively. Note: string.keeper does not seem to work as expected with patterns consisting of more than one byte, e.g. lpeg.P("camel").

Reference:

@see lpeg.stripper

lpeg.replacer


function lpeg.replacer(table: string[][]) ->  Pattern

Returns a pattern that substitutes any first elements of a given pair by its second element.

The latter can be a string, a hashtable, or a function (whatever fits with lpeg.Cs).

Note: Choose the order of elements in table with care. Due to LPEG's matching the leftmost element of disjunction first it might turn out to be as crucial as in the following example:

Example:

local str = "Luxury Yacht"

local rep = {
  [1] = { "Luxury", "Throatwobbler" },
  [2] = { "Yacht", "Mangrove" },
}

print(
  "My name is spelled “"
    .. str
    .. "”, but it's pronounced “"
    .. lpeg.replacer(rep):match(str)
    .. "”."
)

str = "aaababaaba"
local rep1 = {
  { "a", "x" },
  { "aa", "y" },
}

local rep2 = {
  { "aa", "y" },
  { "a", "x" },
}

print(lpeg.replacer(rep1):match(str))
print(lpeg.replacer(rep2):match(str))

Reference:

lpeg.times


function lpeg.times()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.tsplitat


function lpeg.tsplitat()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.tsplitter


function lpeg.tsplitter()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.utfchartabletopattern


function lpeg.utfchartabletopattern()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!

lpeg.utfreplacer


function lpeg.utfreplacer()

Reference:

😱 Types incomplete or incorrect? 🙏 Please contribute!