Skip to content

Commit

Permalink
fix: tmp fix transpiler to run sysinfo program
Browse files Browse the repository at this point in the history
  • Loading branch information
pgagnidze committed May 31, 2023
1 parent 46af6cc commit 95c9ebf
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions ena/transpiler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ local handlers = {
return node.value
end,
["string"] = function(transpiler, node, indentLevel, indent)
-- TODO: replace \ with \\ and " with \"
node.value = string.gsub(node.value, "\\", "\\\\")
return '"' .. node.value .. '"'
end,
["nil"] = function(transpiler, node, indentLevel, indent)
Expand Down Expand Up @@ -151,9 +151,14 @@ local handlers = {
op = "or"
elseif op == "!=" then
op = "~="
elseif op == "+" then -- TODO: handle variables that can be strings or numbers
if node.firstChild.tag == "string" or node.secondChild.tag == "string" then
op = ".."
elseif op == "+" then
-- Check if either operand is a string or a variable
if node.firstChild.tag == "string" or node.firstChild.tag == "variable" or
node.secondChild.tag == "string" or node.secondChild.tag == "variable" then
-- Generate code that checks the type of the operands at runtime
return "(function() local a = " .. transpiler:transpile(node.firstChild, indentLevel) ..
"; local b = " .. transpiler:transpile(node.secondChild, indentLevel) ..
"; if type(a) == 'string' or type(b) == 'string' then return a .. b else return a + b end end)()"
end
end
return transpiler:transpile(node.firstChild, indentLevel) ..
Expand Down

0 comments on commit 95c9ebf

Please sign in to comment.