🩹 [Patch]: Reserved words in Lua input now detected with option to skip validation (#6)
ConvertFrom-Lua now validates that bare identifier keys and variable names are not Lua reserved words, throwing a clear error by default. A new -SkipValidation switch allows lenient import of out-of-spec data, emitting per-occurrence warnings instead. Enum string serialization no longer double-escapes backslashes.
- Fixes #5
Changed: Reserved word validation on deserialization
ConvertFrom-Lua now rejects bare reserved words used as table keys or assignment variable names — matching the Lua 5.4 §3.1 grammar rules. Previously, invalid Lua like { end = 1 } or while = 42 was silently parsed.
# Default — throws a terminating error
ConvertFrom-Lua -InputObject '{ end = 1 }'
# Error: Reserved word 'end' cannot be used as a bare identifier key in a Lua table.
# Use bracket notation: [\"end\"] = value.Bracket-notation keys with reserved word strings remain fully supported:
ConvertFrom-Lua -InputObject '{ [\"end\"] = 1, [\"while\"] = 2 }' -AsHashtable
# Returns: @{ end = 1; while = 2 }New: -SkipValidation switch for lenient import
When importing data that may not be spec-compliant, use -SkipValidation to suppress errors. Each reserved word occurrence produces its own warning, and parsing continues normally.
ConvertFrom-Lua -InputObject '{ end = 1, while = 2 }' -AsHashtable -SkipValidation
# WARNING: Reserved word 'end' used as a bare identifier key at position 2.
# WARNING: Reserved word 'while' used as a bare identifier key at position 11.
# Returns: @{ end = 1; while = 2 }Fixed: Enum string escaping no longer double-escapes backslashes
ConvertTo-Lua -EnumsAsStrings previously produced \\\\ instead of \\ for backslashes in enum string representations due to an incorrect -replace pattern.
Technical Details
ConvertFrom-Lua.ps1: Added-SkipValidationswitch parameter, threaded toConvertFrom-LuaTablevia-SkipValidation:$SkipValidation.ConvertFrom-LuaTable.ps1: Added-SkipValidationparameter. Stored as$script:luaSkipValidationfor use by recursive parser functions. Added$reservedWordsarray and validation after variable name extraction in the assignment parsing path — throws or warns based on skip flag.Read-LuaTable.ps1: Added$reservedWordsarray and validation after bare identifier +=detection — throws or warns based on$script:luaSkipValidation.ConvertTo-LuaTable.ps1: Fixed enum escaping:-replace '\\', '\\\\'→-replace '\\', '\\'.returnkeyword note:returnis consumed as a leading keyword before assignment detection (forreturn { ... }patterns), soreturn = 42triggers a different parse error rather than the reserved word check. Tests usewhileas the second assignment variable test word.- Tests: 8 new tests — 5 for default throw behavior (bare table keys ×2, bracket notation positive, assignment variables ×2), 3 for
-SkipValidation(bare key warning, assignment warning, multiple warnings with count assertion)."