Skip to content

Commit d750a9a

Browse files
Address PR review feedback
- Assignment parser now accepts semicolons between statements (A = 1; B = 2) - Assignment-detection lookahead uses Skip-LuaWhitespace to handle comments between identifier and '=' - Added tests for both scenarios
1 parent 3fb261f commit d750a9a

2 files changed

Lines changed: 32 additions & 6 deletions

File tree

src/functions/private/ConvertFrom-LuaTable.ps1

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@
6363
$tryIdent = $script:luaString.Substring($script:luaPos, $tryPos - $script:luaPos)
6464
# Check it's not a keyword that starts a value (true/false/nil)
6565
if ($tryIdent -notin 'true', 'false', 'nil') {
66-
# Skip whitespace after identifier to check for '='
67-
$peekPos = $tryPos
68-
while ($peekPos -lt $script:luaString.Length -and
69-
$script:luaString[$peekPos] -match '\s') {
70-
$peekPos++
71-
}
66+
# Skip whitespace and comments after identifier to check for '='
67+
# Use Skip-LuaWhitespace with save/restore to handle comments
68+
$peekSavedPos = $script:luaPos
69+
$script:luaPos = $tryPos
70+
Skip-LuaWhitespace
71+
$peekPos = $script:luaPos
72+
$script:luaPos = $peekSavedPos
7273
# Check for '=' but not '=='
7374
if ($peekPos -lt $script:luaString.Length -and
7475
$script:luaString[$peekPos] -eq '=' -and
@@ -112,7 +113,13 @@
112113
$value = Read-LuaValue
113114
$assignments[$varName] = $value
114115

116+
# Consume optional semicolons between assignment statements
115117
Skip-LuaWhitespace
118+
while ($script:luaPos -lt $script:luaString.Length -and
119+
$script:luaString[$script:luaPos] -eq ';') {
120+
$script:luaPos++
121+
Skip-LuaWhitespace
122+
}
116123
}
117124

118125
if ($script:luaAsPSCustomObject) {

tests/Lua.Tests.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,25 @@ B = { val = 2 }
452452
$result.My_Addon_DB.enabled | Should -BeTrue
453453
}
454454

455+
It 'Parses semicolon-separated assignment statements' {
456+
$lua = 'A = 1; B = 2; C = "three"'
457+
$result = ConvertFrom-Lua -InputObject $lua -AsHashtable
458+
$result.A | Should -Be 1
459+
$result.B | Should -Be 2
460+
$result.C | Should -Be 'three'
461+
}
462+
463+
It 'Parses assignments with comment between identifier and equals' {
464+
$lua = @'
465+
A --[[ comment ]]
466+
= { val = 1 }
467+
B = { val = 2 }
468+
'@
469+
$result = ConvertFrom-Lua -InputObject $lua -AsHashtable
470+
$result.A.val | Should -Be 1
471+
$result.B.val | Should -Be 2
472+
}
473+
455474
It 'Does not treat true/false/nil as assignments' {
456475
$result = ConvertFrom-Lua -InputObject 'true'
457476
$result | Should -BeTrue

0 commit comments

Comments
 (0)