Why we have ParseError when pass string variable to query

Does anyone know why I would get an parse error here?

function widgets.headerMention(pageName)
  pageName = pageName or editor.getCurrentPage()
  editor.flashNotification(pageName)
  local DAILY_BASE_PATH = "Journal/Day/" -- Define base path locally

  if not string.startsWith(pageName, DAILY_BASE_PATH) then
    -- Not a daily note, return empty widget
    return widget.new { markdown = "" }
  end

  local dateStr = string.sub(pageName, #DAILY_BASE_PATH + 1)

  -- Query for headers matching the date string

  local query_str = string.format([[
    from index.tag "header"
    where _.name == "%s"
  ]], dateStr)
  
  local headers = query query_str

  local md = ""
  if #headers > 0 then
    -- Assuming templates.header exists and formats a single header item
    md = "## Pages Today\n"
       .. template.each(headers, templates.header)
  else
    md = "" -- No matching headers found
  end

  return widget.new {
    markdown = md
  }
end

From my understanding (as well as the documentation), query[[]] is the same as query some_str. Why would it not work here?

This is an already raised question in the chat of Forum, I just recreate a post here for easier reference of other people stumble on this question. Below is the answer from Zef:


two issues:

  • Parse Error: In Lua parentheses can be omitted for function calls only for literal strings and tables, so variables won’t work (print “Hello” yes, print name no)
  • while in regular Lua query[[bla]] just means “call the query function on the bla” string, in Space Lua it’s actually parsed differently. It doesn’t actually call a query function but is handled differently. It would actually be possible to also support query(someVar) but it doesn’t today