Module:MapBranchingTable

local getArgs = require("Module:GetArgs") local format = require("Module:StringInterpolation").format

local templates = {

table_header = Branching Rules !colspan="2"|Nodes||Rules ,

table_footer = "\n|}",

table_row_start = ${from},

table_row = style="text-align:center;"|${to}||${rules},

}

function formatTable(args) local branching = {} for route, rules in pairs(args) do       local from, to = route:match("(%S+)%s*->%s*(%S+)") if branching[from] then branching[from][to] = rules else branching[from] = {} branching[from][to] = rules end end local rows = {} for from, tos in pairs(branching) do       table.insert(rows, format{            templates.table_row_start,            rowspan = 3,            from = from,        }) local first = true for to, rules in pairs(tos) do           table.insert(rows, format{                templates.table_row,                separator = first and "|-\n" or "",                to = to,                rules = rules,            }) first = false end end return templates.table_header .. table.concat(rows, "\n") .. templates.table_footer end

local MapBranchingTable = {}

function MapBranchingTable.format(frame, args_) local args = args_ or getArgs{frame = frame:getParent} return formatTable(args) end

-- MapBranchingTable.t = MapBranchingTable.format(nil, { ["1 -> 2"] = "..." })

return MapBranchingTable