Skip to content

Latest commit

 

History

History
120 lines (72 loc) · 2.42 KB

File metadata and controls

120 lines (72 loc) · 2.42 KB
description Lua keyword helpers.

keyword

Lua keyword helpers.

Usage

kw = require "mods.keyword"

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

Functions

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.

iskeyword(v)

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") --> false

isidentifier(v)

Return 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") --> false

kwlist()

Return Lua keywords as a mods.List.

Return:

  • words (mods.List<string>): List of Lua keywords.

Example:

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

kwset()

Return Lua keywords as a mods.Set.

Return:

  • words (mods.Set<string>): Set of Lua keywords.

Example:

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

normalize_identifier(s)

Normalize 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"