lpeg.V
Lua function

lpeg.V

Summary

Creates a non-terminal variable for a grammar

Prototype

lpeg.V (v)



Description

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.

The call lpeg.V(v) creates a pattern that represents the nonterminal (or variable) with index v in a grammar. Because the grammar still does not exist when this function is evaluated, the result is an open reference to the respective rule.

A table is *fixed* when it is converted to a pattern (either by calling lpeg.P or by using it wherein a pattern is expected). Then every open reference created by lpeg.V(v) is corrected to refer to the rule indexed by v in the table.

For example:

-- Grammar
local Exp, Term, Factor = lpeg.V"Exp", lpeg.V"Term", lpeg.V"Factor"
G = lpeg.P{ Exp,
Exp = lpeg.Ct(Factor * (FactorOp * Factor)^0);
Factor = lpeg.Ct(Term * (TermOp * Term)^0);
Term = Number + Open * Exp * Close;
}



See Also ...

Topics

DOC_lua_bc Lua bc (big number) functions
DOC_lua_bit Lua bit manipulation functions
DOC_lua_lpeg Lua LPEG library
DOC_lua_package Lua package functions
DOC_lua_rex Lua PCRE regular expression functions
DOC_lua Lua script extensions
DOC_lua_string Lua string functions
DOC_lua_tables Lua table functions
DOC_lua_utils Lua utilities
DOC_regexp Regular Expressions
DOC_scripting Scripting

Lua functions

LUA_lpeg.C lpeg.C (Creates a simple capture)
LUA_lpeg.Carg lpeg.Carg (Creates an argument capture)
LUA_lpeg.Cb lpeg.Cb (Creates a back capture)
LUA_lpeg.Cc lpeg.Cc (Creates a constant capture)
LUA_lpeg.Cf lpeg.Cf (Creates a fold capture)
LUA_lpeg.Cg lpeg.Cg (Creates a group capture)
LUA_lpeg.Cmt lpeg.Cmt (Creates a match-time capture)
LUA_lpeg.Cp lpeg.Cp (Creates a position capture)
LUA_lpeg.Cs lpeg.Cs (Creates a substitution capture)
LUA_lpeg.Ct lpeg.Ct (Creates a table capture)
LUA_lpeg.locale lpeg.locale (Returns a table of patterns matching the current locale)
LUA_lpeg.match lpeg.match (Matches a pattern against a string)
LUA_lpeg.P lpeg.P (Converts a value into a pattern)
LUA_lpeg.print lpeg.print (Outputs debugging information to stdout)
LUA_lpeg.R lpeg.R (Returns a pattern that matches a range of characters)
LUA_lpeg.S lpeg.S (Returns a pattern that matches a set of characters)
LUA_lpeg.type lpeg.type (Tests if a value is a pattern)
LUA_lpeg.version lpeg.version (Returns the LPeg version)

(Help topic: lua=lpeg.V)

DOC_contents Documentation contents page