Module:සියවස් පරික්ෂාව

From Wikisource
Jump to navigation Jump to search

{{සියවස් පරික්ෂාව}} සඳහා අවශ්‍ය මොඩියුලය


local getArgs = require('Module:Arguments').getArgs
local p = {}

local function parikshaawa(args)
	-- return "TRUE"
	-- return "FALSE"
    local input = args["ආදානය"]
	local func = args["ශ්‍රිතය"]

    if input == nil then
        input = ""
    end
    if func == nil then
        func = "0"
    end

    if func == "3" then
        -- m = input:match("^[(ක්‍රිස්තු)]*[ ]*[(වර්ෂ|පූර්ව)]* (%d+) වන සියවස$")
        m = input:match("^ක්‍රිස්තු පූර්ව (%d+) වන සියවස$")
        if m ~= nil then
            return 1
        else
            m = input:match("^(%d+) වන සියවස$")
            if m ~= nil then
                return 1
            else
                -- m = input:match("^(%d+)[srt][tdh] century$")
                m = input:match("^(%d+)[srt][tdh] century[ ]*[B]*[C]*[E]*$")
                if m ~= nil then
                    return 1
                end
            end
        end
        -- ඉහත පරීක්ෂාවට හසු නොවේ නම් පිළිතුර 0 (බිංදුව) වෙයි.
        return 0
    elseif func == "2" then
        m = input:match("^ක්‍රිස්තු පූර්ව (%d+) වන සියවස$")
        if m ~= nil then
            return m
        else
            m = input:match("^(%d+) වන සියවස$")
            if m ~= nil then
                return m
            else
                m = input:match("^(%d+)[srt][tdh] century[ ]*[B]*[C]*[E]*$")
                if m ~= nil then
                    return m
                end
            end
        end
        return "FALSE"
    elseif func == "1" then
        m = input:match("^ක්‍රිස්තු පූර්ව (%d+) වන සියවස$")
        if m ~= nil then
            return 1 - m
        else
            m = input:match("^(%d+) වන සියවස$")
            if m ~= nil then
                return m
            else
                m = input:match("^(%d+)[srt][tdh] century[ ]*[B]*[C]*[E]*$")
                if m ~= nil then
                    if input:match("^.*BCE.*$") then
                        return 1 - m
                    else
                        return m
                    end
                end
            end
        end
        return "FALSE"
        -- return "දෝෂය: තවම සාදා අවසන් කොට නොමැත."
    elseif func == "0" then
        m = input:match("^ක්‍රිස්තු පූර්ව (%d+) වන සියවස$")
        if m ~= nil then
            return "ක්‍රිස්තු පූර්ව " .. (m * 100) - 1
        else
            m = input:match("^(%d+) වන සියවස$")
            if m ~= nil then
                return (m * 100) - 1
            else
                m = input:match("^(%d+)[srt][tdh] century[ ]*[B]*[C]*[E]*$")
                if m ~= nil then
                    if input:match("^.*BCE.*$") then
                        return "ක්‍රිස්තු පූර්ව " .. (m * 100) - 1
                    else
                        return (m * 100) - 1
                    end
                end
            end
        end
        return "FALSE"
        -- return "දෝෂය: තවම සාදා අවසන් කොට නොමැත."
    else
        return func
        -- return "දෝෂය: ශ්‍රිතය සඳහා ලබා දී ඇති පැරාමිතිය හඳුනාගත නොහැකිය."
    end
    

	-- mw.ustring.match(input, '^(%d)* වන සියවස$')

--	if retVal ~= nil then
--		retVal = "TRUE"
--	else
--		retVal = "FALSE"
--	end
	return retVal
end

function p.main(frame)
	local args = getArgs(frame)
	return p._main(args)
end

function p._main(args)
	return parikshaawa(args)
end

return p