Skip to content

Yue auto remove extra parentheses when not intent #206

@GokuHiki

Description

@GokuHiki

I like to use () to select only the first result when return from a function call.

EX:

gsub_plaintext = (str, search, replace) ->
  local escaped_search = search::gsub("([%%%.%[%]%^%$%(%)%*%+%-%?])", "%%%1")
  local escaped_replace = replace::gsub("%%", "%%%%")
  -- parentheses are used to return only the string result
  return (str::gsub(escaped_search, escaped_replace))

print gsub_plaintext("abc def ghi", "def", "xyz")
print gsub_plaintext("abc def ghi", "def", "%%1")

But, Yuescript auto remove the extra parentheses as:

local gsub_plaintext
gsub_plaintext = function(str, search, replace)
  local escaped_search = search:gsub("([%%%.%[%]%^%$%(%)%*%+%-%?])", "%%%1")
  local escaped_replace = replace:gsub("%%", "%%%%")
  return str:gsub(escaped_search, escaped_replace)  -- the extra parentheses is removed
end

print(gsub_plaintext("abc def ghi", "def", "xyz"))
return print(gsub_plaintext("abc def ghi", "def", "%%1"))

Output:

abc xyz ghi	1
abc %%1 ghi	1

Is this behavior is intended? I think it's better to follows to keep the parentheses to achieve the Lua behavior as intended.

Thanks and regards.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions