Module:Grammar: Difference between revisions

From Caves of Qud Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 4: Line 4:
function p.Main(frame)
function p.Main(frame)
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
  for a, b in string.gmatch(f, "(%w*)[:%.](%w*):?%w*") do
  for a, b in string.gmatch(f.lower(), "(%w*)[:%.](%w*):?%w*") do
   if (a == "player") then
   if (a == "player") then
       return "(player's " .. b .. ")"
       return "(player's " .. b .. ")"

Revision as of 23:04, 30 July 2019


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

function p.Main(frame)
parsedtext = string.gsub(frame.args[1], "=([^=]+)=", function(f)
 for a, b in string.gmatch(f.lower(), "(%w*)[:%.](%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[1][b]
   elseif (a == "verb") then
      local pron = frame.args[2]
      local results = p.isplural(pron)
      if not results then 
	 return "No results!"
      end
      if (results[1]['pseudoplural'] == '0') then
         if (b == "are") then
           return "is"
         else
            return b .. "s"
          end
      else 
         return b
      end
   else
      return "ERROR"
   end
 return "error"
 end
end)
return parsedtext
end

function p.parse(field, pronoun)
    fields = field
    args = {
        where='pronoun="' .. pronoun .. '" 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.isplural(pronoun)
    fields= "pseudoplural"
    args = {
        where='pronoun="' .. pronoun .. '" 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.test(frame)
local strippedstring = "j"
local argument = frame.args[1]
for s in string.gmatch(argument, "=([^=]+)=") do
 strippedstring = strippedstring .. s
end
return strippedstring
end

return p