Context
The Lua 5.4 reference manual §3.1 defines 22 reserved words that cannot be used as identifiers:
and, break, do, else, elseif, end, false, for, function, goto, if, in, local, nil, not, or, repeat, return, then, true, until, while
Both the serializer (ConvertTo-Lua) and the parser (ConvertFrom-Lua) need to handle reserved words correctly:
- Serializer:
Format-LuaKey already emits bracket-quote notation (["end"]) for reserved word keys — ensuring all output is spec-compliant and accepted by any Lua interpreter.
- Parser:
ConvertFrom-Lua does not validate that bare identifier keys and variable names are not reserved words. Invalid Lua like { end = 1 } is silently parsed.
A secondary issue exists in enum string serialization, where backslashes are double-escaped.
Request
What happens
-
ConvertFrom-Lua silently accepts reserved words as bare keys:
ConvertFrom-Lua -InputObject '{ end = 1 }' # Parses — but invalid Lua syntax
ConvertFrom-Lua -InputObject '{ while = "x" }' # Also parses — also invalid
-
ConvertFrom-Lua silently accepts reserved words as assignment variable names:
ConvertFrom-Lua -InputObject 'end = 1' # Parses without error
ConvertFrom-Lua -InputObject 'while = 42' # Parses without error
-
Enum string escaping produces double backslashes due to an incorrect -replace pattern in ConvertTo-LuaTable.
What is expected
-
Default behavior: ConvertFrom-Lua throws a terminating error when a reserved word appears as a bare identifier key or variable name. The error message identifies the word and suggests bracket notation.
-
With -SkipValidation: ConvertFrom-Lua emits a warning for each reserved word encountered but continues parsing and returns the data. This supports lenient import of data that may not be spec-compliant.
-
Bracket-notation keys with reserved word strings ({ ["end"] = 1 }) always work — these are valid Lua.
-
Enum string serialization produces correctly escaped output.
Acceptance criteria
ConvertFrom-Lua throws on reserved words as bare table keys (e.g., { end = 1 }) by default
ConvertFrom-Lua throws on reserved words as assignment variable names (e.g., end = 1) by default
-SkipValidation switch suppresses errors → emits warnings and continues parsing
- Each reserved word occurrence produces its own warning when
-SkipValidation is used
- Bracket-notation keys with reserved word strings continue to parse correctly
Format-LuaKey continues to emit bracket notation for reserved word keys (existing behavior)
- Enum string serialization produces single-escaped backslashes
Technical decisions
-SkipValidation switch on ConvertFrom-Lua. Default behavior is strict — reserved words throw. With -SkipValidation, warnings are emitted per occurrence and parsing continues. This allows users to import out-of-spec data when needed while surfacing the issues via warnings.
Threading via script-scoped state. The -SkipValidation flag is stored as $script:luaSkipValidation alongside existing parser state ($script:luaPos, $script:luaString, etc.). This avoids changing the signature of internal functions (Read-LuaTable, Read-LuaValue) that are called recursively.
Validation in two locations:
Read-LuaTable — checks bare identifier keys inside table constructors ({ end = 1 })
ConvertFrom-LuaTable — checks variable names in assignment statements (end = 1)
Reserved word list placement: Defined locally in each function, matching the existing pattern in Format-LuaKey.
Enum escaping fix: The -replace '\\', '\\\\' pattern is corrected to -replace '\\', '\\'.
return keyword handling: return is consumed as a leading keyword before assignment detection (common in return { ... } patterns), so return = 42 does not trigger the reserved word check — it fails with a different parse error. Tests use while as the second assignment test word.
Implementation plan
ConvertFrom-Lua parameter
Parser validation
Serializer fix
Tests
Context
The Lua 5.4 reference manual §3.1 defines 22 reserved words that cannot be used as identifiers:
Both the serializer (
ConvertTo-Lua) and the parser (ConvertFrom-Lua) need to handle reserved words correctly:Format-LuaKeyalready emits bracket-quote notation (["end"]) for reserved word keys — ensuring all output is spec-compliant and accepted by any Lua interpreter.ConvertFrom-Luadoes not validate that bare identifier keys and variable names are not reserved words. Invalid Lua like{ end = 1 }is silently parsed.A secondary issue exists in enum string serialization, where backslashes are double-escaped.
Request
What happens
ConvertFrom-Luasilently accepts reserved words as bare keys:ConvertFrom-Luasilently accepts reserved words as assignment variable names:Enum string escaping produces double backslashes due to an incorrect
-replacepattern inConvertTo-LuaTable.What is expected
Default behavior:
ConvertFrom-Luathrows a terminating error when a reserved word appears as a bare identifier key or variable name. The error message identifies the word and suggests bracket notation.With
-SkipValidation:ConvertFrom-Luaemits a warning for each reserved word encountered but continues parsing and returns the data. This supports lenient import of data that may not be spec-compliant.Bracket-notation keys with reserved word strings (
{ ["end"] = 1 }) always work — these are valid Lua.Enum string serialization produces correctly escaped output.
Acceptance criteria
ConvertFrom-Luathrows on reserved words as bare table keys (e.g.,{ end = 1 }) by defaultConvertFrom-Luathrows on reserved words as assignment variable names (e.g.,end = 1) by default-SkipValidationswitch suppresses errors → emits warnings and continues parsing-SkipValidationis usedFormat-LuaKeycontinues to emit bracket notation for reserved word keys (existing behavior)Technical decisions
-SkipValidationswitch onConvertFrom-Lua. Default behavior is strict — reserved words throw. With-SkipValidation, warnings are emitted per occurrence and parsing continues. This allows users to import out-of-spec data when needed while surfacing the issues via warnings.Threading via script-scoped state. The
-SkipValidationflag is stored as$script:luaSkipValidationalongside existing parser state ($script:luaPos,$script:luaString, etc.). This avoids changing the signature of internal functions (Read-LuaTable,Read-LuaValue) that are called recursively.Validation in two locations:
Read-LuaTable— checks bare identifier keys inside table constructors ({ end = 1 })ConvertFrom-LuaTable— checks variable names in assignment statements (end = 1)Reserved word list placement: Defined locally in each function, matching the existing pattern in
Format-LuaKey.Enum escaping fix: The
-replace '\\', '\\\\'pattern is corrected to-replace '\\', '\\'.returnkeyword handling:returnis consumed as a leading keyword before assignment detection (common inreturn { ... }patterns), soreturn = 42does not trigger the reserved word check — it fails with a different parse error. Tests usewhileas the second assignment test word.Implementation plan
ConvertFrom-Luaparameter-SkipValidationswitch parameter toConvertFrom-Lua-SkipValidationtoConvertFrom-LuaTableas a parameter$script:luaSkipValidationinConvertFrom-LuaTablefor use by recursive parser functionsParser validation
$reservedWordsarray and validation check inRead-LuaTableafter bare identifier +=detection: throw or warn based on$script:luaSkipValidation$reservedWordsarray and validation check inConvertFrom-LuaTableafter variable name extraction: throw or warn based on$script:luaSkipValidationSerializer fix
ConvertTo-LuaTable: change-replace '\\', '\\\\'to-replace '\\', '\\'Tests
{ end = 1 }){ while = "loop" }){ ["end"] = 1, ["while"] = 2 })end = 1)while = 42)-SkipValidationallows bare table key with warning-SkipValidationallows assignment variable name with warning