This module is used to store type data for use with several road templates, including {{jct}} and {{routelist row}}. Background information and a summary of the syntax are listed below.

Syntax

rætta

Hierarchy and fields

rætta

At its most basic level, this module is a nested table of strings. At the top is the root table, named for the abbreviation of a country, state, or province. This table stores the type data for a particular place, which is named in the comment in the first line, and is returned at the end of the module. The table is composed of further tables, one per type. The basic syntax for a type table is:

place.type = {shield = "",
              link = "",
              abbr = ""}

The three main fields in a type table are shield, link, and abbr. Generally, shield determines the shield that is displayed, if any; link specifies the target of the link generated by a including module, if any; and abbr determines the displayed abbreviation. Currently, these are the three types used by all countries. By convention, they are always specified, using an empty string if there is no value.

Two additional fields are used in the United States. banner stores the name of the banner file, while width stores a code representing the width of the shield. Unlike the three main fields, these are generally omitted entirely when unused.

Once a type is defined, it can be referred to later in the code. A common idiom used for bannered types is defining the shield to be the shield field of the base type (from Module:Road data/strings/USA/MO):

MO.US = {shield = "US %route%.svg",
         link = "U.S. Route %route% in Missouri",
         abbr = "US %route%",
         width = "expand"}

MO["US-Alt"] = {shield = MO.US.shield,
                link = "U.S. Route %route% Alternate ([dab||%dab%, |]Missouri)",
                abbr = "US %route% Alt.",
                banner = "Alternate plate.svg",
                width = "expand"}

Another common idiom is defining a type alias by setting an entry in the root table equal to a previously defined type (from Module:Road data/strings/HKG):

HKG.Route = {shield = "HK Route%route%.svg",
             link = "Route %route% (Hong Kong)",
             abbr = "Route %route%"}
 
HKG.route = HKG.Route

Parser arguments

rætta

When the parser function of Module:Road data/parser is called, it is passed up to three parameters. The second one is the field to parse, and the last one is a rarely-used option designed for multiple-shield types. The first and most important parameter is a table of arguments collected by the calling module, which generally includes the state, country, or both; the type and number of the route; and a few miscellaneous arguments. This table of arguments forms the basis of the parser's format string syntax.

The table accessible by the strings includes the following entries by default:

  • state: The state or province the route is located in.
  • country: The country the route is located in. If the country is not passed by the calling module, the parser will attempt to include it.

The above entries are primarily used to find the string module itself, so they should not be a concern for module writers.

  • type: The type of the route. This determines the entry of the root table that is used by the parser.
  • route: The route "number". This is easily the most important argument for module writers.

The following entries are used less often:

  • county: The county the route is located in. This is usually used for county routes in the United States.
  • township: This entry is similar in function and utility to the county entry.
  • dab: A tag used to disambiguate the link target. This is mostly used for bannered routes in the United States.
  • denom: This rare entry is used exclusively for West Virginia county routes.

Parser hooks, which will be described later, can add entries to this table that may be used by strings.

Basic string syntax

rætta

The most basic value that can be used for most type table fields is a specially formatted string, which will be referred to in this documentation as a format string. This is the string that will ultimately be parsed and returned by the parser. A format string is an ordinary string object. The power of these strings comes in the form of two special instructions that are recognized by the parser.

The first is anything in %argument% form. The parser will replace such a statement with the value of the argument entry in the arguments table described earlier. This is what allows the route number to be spliced into a shield or link name.

The second special string is in the form of [arg|equals|then|else]. This functions as a rudimentary if-then-else statement. The parser tests the value of arg to see if it is equal to the value specified in equals. equals may be empty, in which case the parser tests the existence of the arg argument. If the result of the test is true, the statement is replaced with the value of the then block. Otherwise, it is replaced with the value of the else block.

The two statements may be combined. The parser will parse the if-then-else statement first, and then perform the argument inclusion. This combination is commonly used with bannered routes in the United States, where the dab argument is tested and the link disambiguation is adjusted accordingly, as follows (from Module:Road data/strings/USA/AL):

AL["US-Bus"] = {shield = "US %route%.svg",
                link = "U.S. Route %route% Business ([dab||%dab%, |]Alabama)",
                abbr = "US-%route% Bus.",
                banner = "Business plate.svg",
                width = "expand"}

When parsing the link field, the parser first checks to see if the dab argument was provided. If so, it replaces the statement with %dab%, . If not, the statement is replaced with the empty string placed in the else block. Then, the parser replaces %route% with the route number and, if the dab argument was provided, %dab% with the value of that argument.

Switching

rætta

Some logic is too complicated to represent with only format strings. This framework provides several methods to express complex data. All of these involve storing a nested table as the value of a field.

The most straightforward functionality provided by nested tables is switching. In its most basic form, the table consists of a series of key-value pairs, with the keys being route numbers and the values being the format strings used by those routes. Usually, the format string returned does not need parsing, but the option is there. A default entry should be provided to handle any route numbers not explicitly stated. The following is a representative example of route-based switching (from Module:Road data/strings/USA/AR):

AR.AR = {shield = {default = "Arkansas %route%.svg",
                   ["917"] = "Arkansas 917-1.svg",
                   ["980"] = "Arkansas 980(Airport).svg"},
         link = "Arkansas Highway %route% [dab||(%dab%)|]",
         abbr = "Hwy. %route%",
         width = "expand"}

In this example, Highways 917 and 980 have non-standard shield names, which are explicitly provided. Other route numbers use the default format.

Switching on other arguments is also allowed. The name of the argument to be used for switching is stated in the arg field of the table. Nesting switches on different arguments is also allowed. A good example that uses both forms of switching can be found in Ontario:

local regionalShields = {arg = "county",
                         ["Essex"] = "Essex County Road %route%.png",
                         ["York"] = "York Regional Road %route%.svg",
                         ["Durham"] = "Durham Regional Road %route%.svg",
                         ["Niagara"] = "Niagara Regional Road %route%.svg",
                         ["Simcoe"] = {["52"] = "Simcoe county road 52.png",
                                       default = "Simcoe County Road %route%.JPG"}}

In this example, which is a shield table that is reused by several types in Ontario, the county argument is used for the primary switch. If the route is in Simcoe County, a second switch is performed, this time on the route number.

Existence testing

rætta

Another use for tables is existence testing. If a table has the ifexists field set to true, the parser will perform existence testing on the result of parsing the default field. If the test fails, the result of parsing the otherwise field is returned. Existence testing may be chained by using a second ifexists table as the value of the first table's otherwise field, and so on. Here's an example of nested existence testing (from Module:Road data/strings/GBR):

GBR.B = {shield = {ifexists = true,
                   default = "UK road B%route%.svg",
                   otherwise = {ifexists = true,
                                default = "UK road B%route%.png"}},
         link = "",
         abbr = "B%route%"}

Due to technical limitations, these string modules cannot contain functions. Rather than force functionality into the string framework, the parser can call functions in a separate hooks module. The functions in this module, Module:Road data/parser/hooks, are more-or-less fully functional functions. The exact functionalities of these hooks are beyond the scope of this documentation. Descriptions of these hooks may be found on their documentation page.

Generally speaking, a hook is called by setting the hook field in a table as equal to the name of a hook. Hooks receive two arguments, both tables: parameters, which is the table in the definition; and args, which is simply the table of arguments normally passed to the parser. The hook returns a string, which is then parsed as usual. A powerful feature of hooks is that they can add arbitrary values to the argument table, which may be referenced in the string returned by the hook. Generally, the format string returned by the hook is specified in some form by the default field of the table, though there are exceptions. Here is an example of a hook (from Module:Road data/strings/MEX):

MEX.SH = {shield = {ifexists = true,
                    arg = "state",
                    SON = "HIGHWAYSON %route%.jpg",
                    NLE = "Nuevo Leon State Highway %route%.PNG",
                    default = ""},
          link = {hook = "mask",
                  mask = "Road data/masks/MEX",
                  base = "state",
                  masked = "fullstate",
                  default = "%fullstate% State Highway %route%"},
          abbr = "SH %route%"}

In this example, the parser will process the link by calling the mask hook. In short, this hook takes the argument referenced in base, passes it through the mask module specified in mask, and stores it in the field in the arguments noted in masked. The hook returns the string given in default, which has access to the fullstate argument added by the hook.

Other functionality

rætta

Functionality exists to display multiple shields for one route, which is used to display tolled and free shields for routes where they differ. This is done by supplying a table with two values, which are listed without indices. The parser is called twice by the calling module, and it returns one shield per call. An example may be found in Texas:

TX.Both = {shield = {"Texas %route%.svg", "Toll Texas %route% new.svg"},
           link = "Texas State Highway %route%",
           abbr = "SH %route%",
           width = 40}

Structure

rætta

Each country has its own module. In the United States and Canada, each state/territory/province also has its own module. Each module begins with a comment stating the name of the country or state, followed by the root table declaration, as follows (from Module:Road data/strings/USA/AS):

-- American Samoa
local AS = {}

The root table is named based on the established abbreviation for the country or state, which is the same as the abbreviation used in the module title. This table stores the various types used in that particular place. Most of the remaining code in the module defines these various types. The module ends by returning the root table:

return AS

Aliasing

rætta

There are two ways to define a type as an alias. If the type is defined within the module, simply set the new type as equal to the type being aliased, as shown above (from Module:Road data/strings/HKG):

HKG.Route = {shield = "HK Route%route%.svg",
             link = "Route %route% (Hong Kong)",
             abbr = "Route %route%"}
 
HKG.route = HKG.Route

If the type is defined in a separate module, such as a state highway type being used in another state's module, a special syntax may be used to refer to that module (from Module:Road data/strings/USA/NJ):

NJ.NY = {alias = {module = "USA/NY", type = "NY"}}

This code sets the NY type as a link to the NY type in Module:Road data/strings/USA/NY. The parser will import that module and process the type as if the original module had declared it itself. The alias declaration may not add or override any data in the type table it points to.

There are a few style guidelines that should be followed:

  1. Align table fields using spaces. All tables should be aligned so that fields line up with each other, as shown in the above examples.
  2. Do not place a table's closing brace on a separate line.
  3. Each table field should be on its own line.
  4. Add spaces to either side of an assignment operator (equals sign).
  5. Leave a blank line between types. Type aliases should be set off from their base type by a blank line, but no blank lines should be placed between the aliases themselves.

--Illinois
local IL = {}

IL.I = {shield = "I-%route%.svg",
        link = {["39"] = "Interstate 39",
                ["41"] = "Interstate 41",
                ["57"] = "Interstate 57",
                ["72"] = "Interstate 72",
                ["88"] = "Interstate 88 (Illinois)",
                ["172"] = "Interstate 172",
                ["255"] = "Interstate 255",
                ["270"] = "Interstate 270 (Illinois–Missouri)",
                ["280"] = "Interstate 280 (Illinois–Iowa)",
                ["294"] = "Interstate 294",
                ["355"] = "Interstate 355",
                ["474"] = "Interstate 474",
                default = {hook = "split",
                           split = 100,
                           above = "Interstate %route% (Illinois)",
                           below = "Interstate %route% in Illinois"}},
        abbr = "I-%route%",
        width = "expand"}

IL["I-Toll"] = {shield = IL.I.shield,
                link = IL.I.link,
                abbr = IL.I.abbr,
                banner = "Toll plate yellow.svg",
                width = "expand"}

IL.BL = {shield = "Business Loop %route%.svg",
         link = "Interstate %route% Business ([dab||%dab%, |]Illinois)",
         abbr = "I-%route% Bus.",
         width = "expand"}

IL["I-Bus"]=IL.BL

IL.US = {shield = "US %route%.svg",
         link = "U.S. Route %route% in Illinois",
         abbr = "US %route%",
         width = "expand"}

IL["US-Alt"] = {shield = IL.US.shield,
                link = "U.S. Route %route% Alternate ([dab||%dab%, |]Illinois)",
                abbr = "US %route% Alt.",
                banner = "Alt plate.svg",
                width = "expand"}

IL["US-Bus"] = {shield = IL.US.shield,
                link = "U.S. Route %route% Business ([dab||%dab%, |]Illinois)",
                abbr = "US %route% Bus.",
                banner = "Business plate.svg",
                width = "expand"}

IL["US-Byp"] = {shield = IL.US.shield,
                link = "U.S. Route %route% Bypass ([dab||%dab%, |]Illinois)",
                abbr = "US %route% Byp.",
                banner = "Bypass plate.svg",
                width = "expand"}

IL["US-City"] = {shield = IL.US.shield,
                link = "U.S. Route %route% City ([dab||%dab%, |]Illinois)",
                abbr = "US %route% City",
                banner = "City plate.svg",
                width = "expand"}

IL["US-Truck"] = {shield = IL.US.shield,
                link = "U.S. Route %route% Truck ([dab||%dab%, |]Illinois)",
                abbr = "US %route% Truck",
                banner = "Truck plate.svg",
                width = "expand"}

IL["US-Hist"] = {shield = {["66"] = "US 66 (historic).svg",
                           default = ""},
                 link = "U.S. Route %route% in Illinois",
                 abbr = "Historic US %route%[dab|| (%dab%)|]",
                 width = 16}

IL["US 1926"] = {shield = "US %route% Illinois 1926.svg",
                 link = IL.US.link,
                 abbr = IL.US.abbr,
                 width = "US1926"}

IL.IL = {shield = "Illinois %route%.svg",
         link = "Illinois Route %route%",
         abbr = "IL %route%",
         width = "expand"}

IL["IL 1926"] = {shield = "Illinois %route% (1926).svg",
         		link = IL.IL.link,
         		abbr = IL.IL.abbr}

IL.Toll = {shield = "Indiana Toll Road logo 1968.svg",
           link = "Indiana Toll Road",
           abbr = "Indiana Toll Road"}

IL.Skyway = {shield = "Chicago Skyway logo.svg",
             link = "Chicago Skyway",
             abbr = "Chicago Skyway"}

IL.Tour = {shield = {default = "Great Lakes Circle Tour.svg",
                     LSCT = "Lake Superior Circle Tour.svg",
                     LMCT = "Lake Michigan Circle Tour.svg",
                     LHCT = "Lake Huron Circle Tour.svg",
                     LECT = "Lake Erie Circle Tour.svg",
                     ["LSCT-Spur"] = "Lake Superior Circle Tour brown.svg",
                     ["LMCT-Spur"] = "Lake Michigan Circle Tour brown.svg",
                     ["LHCT-Spur"] = "Lake Huron Circle Tour brown.svg"},
           link = {default = "Great Lakes Circle Tour",
                   LSCT = "Lake Superior Circle Tour",
                   LMCT = "Lake Michigan Circle Tour",
                   LHCT = "Lake Huron Circle Tour",
                   LECT = "Lake Erie Circle Tour",
                   ["LSCT-Spur"] = "Lake Superior Circle Tour",
                   ["LMCT-Spur"] = "Lake Michigan Circle Tour",
                   ["LHCT-Spur"] = "Lake Huron Circle Tour"},
           abbr = {default = "GLCT",
                   LSCT = "LSCT",
                   LMCT = "LMCT",
                   LHCT = "LHCT",
                   LECT = "LECT",
                   ["LSCT-Spur"] = "LSCT Spur",
                   ["LMCT-Spur"] = "LMCT Spur",
                   ["LHCT-Spur"] = "LHCT Spur"}
           }

IL.Lincoln = {shield = "LincolnHighwayMarker.svg",
              link = "Lincoln Highway in Illinois",
              abbr = "Lincoln Highway",
              width = 14}

IL.National = {shield = "National Road Sign cropped.JPG", --should be improved
              link = "National Road",
              abbr = "Historic National Road"}

IL.GRR = {shield = "GreatRiverRoad.svg",
          link = "Great River Road",
          abbr = "Great River Road [route||(%route% Route)|]",
          banner = {arg = "route",
                    default = "",
                    National = "National Route plate.svg",
                    ["Alternate National"] = "Alternate plate.svg",
                    Alternate = "Alternate plate.svg"}}

IL["GRR-Spur"] = {shield = "GreatRiverRoad brown.svg",
                  link = "Great River Road",
                  abbr = "Great River Road Spur",
                  banner = "Spur plate brown.svg"}

IL.LHT = {shield = "Lincoln Heritage Trail.png",
          link = "Lincoln Heritage Trail",
          abbr = "Lincoln Heritage Trail [route||(%route%)|]"}

IL.MGR = {shield = "",
          link = "Meeting of the Great Rivers Scenic Route",
          abbr = "Meeting of the Great Rivers"}

IL.IRR = {shield = "",
          link = "Illinois River Road",
          abbr = "Illinois River Road"}

IL.CR = {shield = "CR %route% jct.svg",
         link = "",
         abbr = "CR %route%"}

IL.CKC = {shield = "Illinois 110.svg",
          link = "Chicago–Kansas City Expressway",
          abbr = "IL 110 (CKC)",
          banner = "CKC plate.svg",
          width = "square"}

return IL