| description | Lua keyword helpers. |
|---|
Lua keyword helpers.
kw = require "mods.keyword"
kw.iskeyword("local")) --> true
kw.isidentifier("hello_world") --> true| Function | Description |
|---|---|
iskeyword(v) |
Return true when v is a reserved Lua keyword. |
isidentifier(v) |
Return true when v is a valid non-keyword Lua identifier. |
kwlist() |
Return Lua keywords as a mods.List. |
kwset() |
Return Lua keywords as a mods.Set. |
normalize_identifier(s) |
Normalize an input into a safe Lua identifier. |
Return true when v is a reserved Lua keyword.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
kw.iskeyword("function") --> true
kw.iskeyword("hello") --> falseReturn true when v is a valid non-keyword Lua identifier.
Parameters:
v(any): Value to validate.
Return:
ok(boolean): Whether the check succeeds.
Example:
kw.isidentifier("hello_world") --> true
kw.isidentifier("local") --> falseReturn Lua keywords as a mods.List.
Return:
words(mods.List<string>): List of Lua keywords.
Example:
kw.kwlist():contains("and") --> trueReturn Lua keywords as a mods.Set.
Return:
words(mods.Set<string>): Set of Lua keywords.
Example:
kw.kwlset():contains("and") --> trueNormalize an input into a safe Lua identifier.
Parameters:
s(string): Input string.
Return:
ident(string): Normalized Lua identifier.
Example:
kw.normalize_identifier(" 2 bad-name ") --> "_2_bad_name"