diff options
| author | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-08 15:41:05 -0700 |
|---|---|---|
| committer | Bruce Hill <bitbucket@bruce-hill.com> | 2018-04-08 15:41:55 -0700 |
| commit | fd621a1062c12b808efd7f8adf1957e0fe978ecc (patch) | |
| tree | 6e19a251c58c1187a128989f983073bb214052db /nomsu.lua | |
| parent | a49e97f0e3a8b69afbc375fac7e04fe49aaf0591 (diff) | |
Cleaned up LHS of "." operator to avoid adding unnecessary parens so
Lua's parser doesn't get confused by (x).y = 1.
Diffstat (limited to 'nomsu.lua')
| -rw-r--r-- | nomsu.lua | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -776,7 +776,7 @@ do return nil end buff = buff .. (function() - if bit.type == "Var" or bit.type == "List" or bit.type == "Dict" or bit.type == "IndexChain" then + if bit.type == "Var" or bit.type == "List" or bit.type == "Dict" then return "\\" .. nomsu else return "\\(" .. nomsu .. ")" @@ -1192,9 +1192,17 @@ do error(tostring(line) .. ": Cannot index " .. tostring(colored.yellow(src)) .. ", since it's not an expression.", 0) end if i == 1 then - insert(items, "(" .. tostring(lua.expr) .. ")") + if lua.expr:sub(-1, -1) == "}" or lua.expr:sub(-1, -1) == '"' then + insert(items, "(" .. tostring(lua.expr) .. ")") + else + insert(items, lua.expr) + end else - insert(items, "[ " .. tostring(lua.expr) .. "]") + if item.type == 'Text' and #item.value == 1 and type(item.value[1]) == 'string' and item.value[1]:match("^[a-zA-Z_][a-zA-Z0-9_]$") then + insert(items, "." .. tostring(item.value[1])) + else + insert(items, "[ " .. tostring(lua.expr) .. "]") + end end end return { |
