]> git.lizzy.rs Git - metalua.git/commitdiff
ast_to_src handles "string literal":method()
authorshviller <shviller@gmail.com>
Fri, 3 Oct 2014 17:09:46 +0000 (21:09 +0400)
committershviller <shviller@gmail.com>
Fri, 3 Oct 2014 17:09:46 +0000 (21:09 +0400)
ast_to_src wraps "string literal" in parens to produce valud lua syntax.

metalua/compiler/ast_to_src.mlua

index b363cb1e71b77bbc1a80ba4f8c1a4c1defc7a983..5bf96650a97b19a575d19ce0b6ab6fd7372cbac4 100644 (file)
@@ -439,13 +439,19 @@ end
 
 function M:Invoke (node, f, method)
    -- single string or table literal arg ==> no need for parentheses. --
-   local parens
+   local parens, wrap
+   match node with
+   | `Invoke{ `String{_}, ...} -> wrap = true
+   | _ -> wrap = false
+   end
    match node with
    | `Invoke{ _, _, `String{_} }
    | `Invoke{ _, _, `Table{...}} -> parens = false
    | _ -> parens = true
    end
+   self:acc    (wrap and "(" or "")
    self:node   (f)
+   self:acc    (wrap and ")" or "")
    self:acc    ":"
    self:acc    (method[1])
    self:acc    (parens and " (" or  " ")