From: shviller Date: Fri, 3 Oct 2014 17:09:46 +0000 (+0400) Subject: ast_to_src handles "string literal":method() X-Git-Url: https://git.lizzy.rs/?a=commitdiff_plain;h=30603a82a02c4c2e3b63032eec1a6d1d99e10013;p=metalua.git ast_to_src handles "string literal":method() ast_to_src wraps "string literal" in parens to produce valud lua syntax. --- diff --git a/metalua/compiler/ast_to_src.mlua b/metalua/compiler/ast_to_src.mlua index b363cb1..5bf9665 100644 --- a/metalua/compiler/ast_to_src.mlua +++ b/metalua/compiler/ast_to_src.mlua @@ -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 " ")