From 30603a82a02c4c2e3b63032eec1a6d1d99e10013 Mon Sep 17 00:00:00 2001 From: shviller Date: Fri, 3 Oct 2014 21:09:46 +0400 Subject: [PATCH] ast_to_src handles "string literal":method() ast_to_src wraps "string literal" in parens to produce valud lua syntax. --- metalua/compiler/ast_to_src.mlua | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 " ") -- 2.44.0