Documentation icon دستاویز [تخلیق]
local p = {}

local format = mw.ustring.format

local typesModule = require "Module:Infobox road/abbrev/defs"
Country = typesModule.Country
Type = typesModule.Type
Abbr = typesModule.Abbr

local abbrs = Country:new()
do -- Abbreviation definitions
    function abbrs:typeOverride(args)
        local type = args.type
        local state = args.state
        if not(state) then return end
        local stateVarTypes = {"%s", "%s-old", "%s 1926", "%s 1940", "%s 1948", "%s 1950", "%s 1955"}
        local typesToCheck = {}
        for i,v in ipairs(stateVarTypes) do
            local type = format(v, state)
            typesToCheck[type] = true
        end
        if typesToCheck[type] then
            return self["SR"]
        else
            return nil
        end
    end
    
    do -- Interstates
        local type = Type:new{formatStr = "I-%s"}
        abbrs["I"] = type
        abbrs["Interstate"] = type
        abbrs["I 1957"] = type
        type["HI"] = Abbr:new{formatStr = "H-%s"}
        type["PR"] = Abbr:new{formatStr = "PRI-%s"}
    end -- Interstates
    
    abbrs["Future"] = Abbr:new{formatStr = "Future I-%s"} -- Future Interstates
    
    do -- U.S. Routes
        local type = Type:new{formatStr = "US %s"}
        abbrs["US"] = type
        abbrs["US 1926"] = type
        abbrs["US 1948"] = type
        abbrs["US 1950"] = type
        do -- US-x
            local states = {"AL", "ID", "KS", "OK", "TN", "UT"}
            local abbr = Abbr:new{formatStr = "US-%s"}
            for i,v in ipairs(states) do
                type[v] = abbr
            end
        end -- US-x
    end -- U.S. Routes
    
    abbrs["USBR"] = Type:new{formatStr = "USBR %s"} -- U.S. Bicycle Routes
    
    abbrs["NER"] = Abbr:new{formatStr = "Route %s"} -- New England Routes
    
    do -- State highways
        local type = Type:new{formatStr = "%s %s", formatArgs = {"state", "route"}}
        do
            local types = {"SH", "SR", "Route", "M", "K", "U", "SH-old", "SR-old", "Route-old", "DE 1964", "LA 1990", "M-old", "M 1919", "M 1926", "M 1948",
                           "NJ 1956", "NY 1927", "NY 1960", "NC 1945", "NC 1957", "SC 1971", "Town"}
            for i,v in ipairs(types) do
                abbrs[v] = type
            end
        end
        
        do -- SR-x
            local abbr = Abbr:new{formatStr = "SR-%s"}
            type["AL"] = abbr
        end -- SR-x
        
        do -- SR x
            local abbr = Abbr:new{formatStr = "SR %s"}
            local states = {"AZ", "CA", "FL", "GA", "IN", "ME", "NV", "OH", "TN", "VA", "WA"}
            for i,v in ipairs(states) do
                type[v] = abbr
            end
        end -- SR x
        
        do -- SH x
            local abbr = Abbr:new{formatStr = "SH %s"}
            type["CO"] = abbr
            type["TX"] = abbr
        end -- SH x
        
        do -- SH-x
            local abbr = Abbr:new{formatStr = "SH-%s"}
            type["ID"] = abbr
            type["OK"] = abbr
        end -- SH-x
        
        do -- Route x
            local abbr = Abbr:new{formatStr = "Route %s"}
            local states = {"CT", "HI", "MA", "MO", "NJ", "RI"}
            for i,v in ipairs(states) do
                type[v] = abbr
            end
        end -- Route x
        
        do -- <State>-x
            local abbr = Abbr:new{formatStr = "%s-%s", formatArgs = {"state", "route"}}
            type["AK"] = abbr
            type["PR"] = abbr
        end -- <State>-x
        
        do -- New York
            local function dabStr(args)
                local dab = args.dab
                if dab and #dab > 0 then
                    args.dabStr = format(" (%s)", dab)
                else
                    args.dabStr = ""
                end
            end
            type["NY"] = Abbr:new{formatStr = "NY&nbsp;%s%s", formatArgs = {"route", "dabStr"}, preprocessors = {dabStr}}
        end -- New York
        
        type["VI"] = Abbr:new{formatStr = "Highway&nbsp;%s"} -- Virgin Islands
        type["AR"] = Abbr:new{formatStr = "Hwy.&nbsp;%s"} -- Arkansas
        type["GU"] = Abbr:new{formatStr = "GH-%s"} -- Guam
        type["IA"] = Abbr:new{formatStr = "Iowa&nbsp;%s"} -- Iowa
        type["KS"] = Abbr:new{formatStr = "K-%s"} -- Kansas
        type["MI"] = Abbr:new{formatStr = "M-%s"} -- Michigan
        type["NE"] = Abbr:new{formatStr = "N-%s"} -- Nebraska
        type["WI"] = Abbr:new{formatStr = "WIS&nbsp;%s"} -- Wisconsin
        type["WY"] = Abbr:new{formatStr = "WYO&nbsp;%s"} -- Wyoming
        type["UT"] = Abbr:new{formatStr = "SR-%s", exceptions = {["281-320"] = "SR-281 to SR-320"}} -- Utah
    end -- State highways
    
    do -- Former routes
        local type = Abbr:new{formatStr = "ex-SR&nbsp;%s"}
        abbrs["Former"] = type
        abbrs["Former Toll"] = type
    end -- Former routes
    
    do -- Secondary routes
        local type = Type:new{formatStr = "SR&nbsp;%s"}
        abbrs["Sec"] = type
        abbrs["Secondary"] = type
        local abbr = Abbr:new{formatStr = "SR-%s"}
        type["MT"] = abbr
        type["TN"] = abbr
    end -- Secondary routes
    
    do -- County routes
        local type = Type:new{formatStr = "CR&nbsp;%s"}
        abbrs["CR"] = type
        type["LA"] = Abbr:new{formatStr = "PR&nbsp;%s"}
        local abbr = Abbr:new{formatStr = "CR-%s"}
        type["AL"] = abbr
        type["ID"] = abbr
    end -- County routes
    
    abbrs["CDH"] = Abbr:new{formatStr = "%s"} -- County Designated Highways (Michigan)
    abbrs["E"] = Abbr:new{formatStr = "E-%s"} -- E-470 (Colorado)
    
    do -- Forest Highways
        local type = Type:new{formatStr = "FH&nbsp;%s"}
        abbrs["FR"] = type
        abbrs["FH"] = type
        abbrs["FFH"] = type
        type["CA"] = Abbr:new{formatStr = "F.H.&nbsp;%s"}
        type["MI"] = Abbr:new{formatStr = "FFH&nbsp;%s"}
    end -- Forest Highways
    
    do -- Toll roads
        local type = Type:new()
        abbrs["Toll"] = type
        type["FL"] = Abbr:new{formatStr = "SR&nbsp;%s"}
        type["PA"] = Abbr:new{formatStr = "PA&nbsp;%s"}
        do -- Texas
            local exceptions = {["1"] = "Loop&nbsp;1", ["183A"] = "183A"}
            type["TX"] = Abbr:new{formatStr = "SH&nbsp;%s", exceptions = exceptions}
        end -- Texas
    end -- Toll roads
    
    abbrs["LA 1924"] = Abbr:new{formatStr = "SR&nbsp;%s"} -- 1924 Louisiana State Routes
    
    do -- Farm to Market Roads
        local abbr = Abbr:new{formatStr = "FM&nbsp;%s"}
        abbrs["FM"] = abbr
        abbrs["Farm"] = abbr
    end -- Farm to Market Roads
    
    abbrs["Link"] = Abbr:new{formatStr = "L-%s"} -- Nebraska Links
    abbrs["Loop"] = Abbr:new{formatStr = "Loop&nbsp;%s"} -- Loops
    abbrs["PSH"] = Abbr:new{formatStr = "PSH&nbsp;%s"} -- Primary State Highways (Washington)
    abbrs["SSH"] = Abbr:new{formatStr = "SSH&nbsp;%s"} -- Secondary State Highways (Washington)
    abbrs["Park"] = Abbr:new{formatStr = "PR&nbsp;%s"} -- Park Roads
    abbrs["Parkway"] = Abbr:new{formatStr = "%s Parkway"} -- Parkways
    
    do -- Ranch to Market Roads
        local abbr = Abbr:new{formatStr = "RM&nbsp;%s"}
        abbrs["RM"] = abbr
        abbrs["Ranch"] = abbr
    end -- Ranch to Market Roads
    
    do -- Recreational Roads
        local type = Type:new{formatStr = "RE&nbsp;%s"}
        abbrs["Rec"] = type
        abbrs["RE"] = type
        type["NE"] = Abbr:new{formatStr = "R-%s"}
    end -- Recreational Roads
    
    do -- Spurs
        local type = Type:new{formatStr = "Spur&nbsp;%s"}
        abbrs["Spur"] = type
        type["NE"] = Abbr:new{formatStr = "S-%s"}
    end -- Spurs
end

p.abbrs = abbrs
return p