Skip to content

keyword ​

Lua keyword helpers.

Usage ​

lua
kw = require "mods.keyword"

kw.iskeyword("local"))         --> true
kw.isidentifier("hello_world") --> true

Dependencies ​

Dependencies below are lazy-loaded 💤 on first access.

Functions ​

FunctionDescription
iskeywordReturn true when s is a reserved Lua keyword.
isidentifierReturn true when s is a valid non-keyword Lua identifier.
kwlistReturn Lua keywords as a mods.List.
kwsetReturn Lua keywords as a mods.Set.
normalize_identifierNormalize an input into a safe Lua identifier.

iskeyword ​

Return true when s is a reserved Lua keyword.

lua
kw.iskeyword("function") --> true
kw.iskeyword("hello") --> false

isidentifier ​

Return true when s is a valid non-keyword Lua identifier.

lua
kw.isidentifier("hello_world") --> true
kw.isidentifier("local") --> false

kwlist ​

Return Lua keywords as a mods.List.

lua
kw.kwlist():contains("and") --> true

kwset ​

Return Lua keywords as a mods.Set.

lua
kw.kwlset():contains("and") --> true

normalize_identifier ​

Normalize an input into a safe Lua identifier.

lua
kw.normalize_identifier(" 2 bad-name ") --> "_2_bad_name"