Module:Grammar

From Caves of Qud Wiki
Revision as of 21:48, 30 July 2019 by Teamtoto (talk | contribs)
Jump to navigation Jump to search

local p = {}
local cargo = mw.ext.cargo

function p.Main(frame)
for a, b in string.gmatch(frame.args[1], "(%w*)[:.](%w*)") do
  if (a == "player") then
     return "(player's " .. b .. ")"
  elseif (a =="pronouns") then
     local results = p.parse(b, frame.args[2])
     if not results then 
	return "No results!"
     end
     return results['0']['possessive']
  elseif (a =="verb") then
     return "todo"
  else
     return "ERROR"
  end
return "error"
end
end

function p.parse(field, pronoun)
    fields='possessive'
    args = {
        --where="pronoun=\"" .. "she/her" .. "\" AND _pageName=\"Gender and Pronouns\"",
        limit='1'
    }
    local result= cargo.query('Pronouns',fields,args)
    if not next(result) then
        return nil
    else
	return result
    end
end

function p.formatResult(result)
local formatted = {}
for k, row in ipairs(result) do
    formatted[k] = row
end
return formatted
end

return p