1 local function snext(t, state)
7 if k ~= "__sorted" then
8 table.insert(t.__sorted, k)
11 table.sort(t.__sorted)
15 for i, v in ipairs(t.__sorted) do
17 key = t.__sorted[i + 1]
34 local function parse_pair(pair, value_first)
35 if pair:sub(1, 1) == "#" then
39 local idx = pair:find(" ")
42 local first, second = pair:sub(1, idx - 1), pair:sub(idx + 1)
43 local c = first:sub(1, 1)
45 if value_first and c ~= "{" and c ~= "%" then
55 function parse_spec(name, value_first)
56 local f = io.open("spec/" .. name, "r")
61 if l:sub(1, 1) == "\t" then
62 local key, val = parse_pair(l:sub(2), value_first)
67 table.insert(top, key)
70 local key, val = parse_pair(l, value_first)
85 local casemap = parse_spec("casemap")
87 function camel_case(snake)
88 if casemap[snake] then
95 local idx = snake:find("_") or #snake + 1
98 .. snake:sub(1, 1):upper()
99 .. snake:sub(2, idx - 1)
101 snake = snake:sub(idx + 1)
107 function apply_prefix(fields, str)
108 return (fields.prefix or "") .. camel_case(str) .. (fields.postfix or "")