|
@@ -1,3 +1,4 @@
|
|
|
+local datafile = require "datafile"
|
|
|
local dir = require "pl.dir"
|
|
|
local path = require "pl.path"
|
|
|
|
|
@@ -44,7 +45,12 @@ end
|
|
|
|
|
|
|
|
|
-- Parameters that do not get inherited.
|
|
|
-local NO_INHERIT = {abstract = true}
|
|
|
+local NO_INHERIT = {
|
|
|
+ abstract = true,
|
|
|
+ core = true,
|
|
|
+ description = true,
|
|
|
+}
|
|
|
+
|
|
|
local MODEL_PATH = path.join(pkar.config_path, "model")
|
|
|
|
|
|
local gen_config = dofile(path.join(MODEL_PATH, "generation.lua"))
|
|
@@ -62,10 +68,16 @@ end
|
|
|
local function parse_model(mod_id)
|
|
|
local hierarchy = {}
|
|
|
|
|
|
- local function traverse(mod_id)
|
|
|
+ local function traverse(mod_id, core)
|
|
|
logger:debug("traversing: " .. mod_id)
|
|
|
- local model = dofile(path.join(
|
|
|
- MODEL_PATH, "typedef", mod_id .. ".lua"))
|
|
|
+ local schema_path = path.join(MODEL_PATH, "schema", mod_id .. ".lua")
|
|
|
+ -- If core is true, or if the schema is not found in the user config,
|
|
|
+ -- look at the core schema.
|
|
|
+ if core or not path.isfile(schema_path) then
|
|
|
+ schema_path = datafile.path(
|
|
|
+ "core_schema/" .. mod_id .. ".lua")
|
|
|
+ end
|
|
|
+ local model = dofile(schema_path)
|
|
|
-- Merge separate generator config
|
|
|
model.gen = gen_config[mod_id]
|
|
|
--model.id = mod_id
|
|
@@ -82,15 +94,18 @@ local function parse_model(mod_id)
|
|
|
|
|
|
table.insert(hierarchy, 1, model)
|
|
|
|
|
|
- if model.broader then traverse(model.broader) end
|
|
|
+ if model.broader then traverse(model.broader)
|
|
|
+ elseif model.core then traverse(mod_id, true) end
|
|
|
end
|
|
|
traverse(mod_id)
|
|
|
|
|
|
local lineage = {} -- Ordered lineage of types, from ancestor to leaf.
|
|
|
local types = {} -- Set of all types.
|
|
|
for _, mod in ipairs(hierarchy) do
|
|
|
- table.insert(lineage, mod.id)
|
|
|
- types[mod.id] = true
|
|
|
+ if not mod.core then
|
|
|
+ table.insert(lineage, mod.id)
|
|
|
+ types[mod.id] = true
|
|
|
+ end
|
|
|
end
|
|
|
|
|
|
local function merge(src, dest)
|
|
@@ -119,17 +134,29 @@ end
|
|
|
local function setup_model()
|
|
|
-- Temp store (set) for property names.
|
|
|
local all_pnames = {}
|
|
|
+
|
|
|
-- Collect all type names from config file names.
|
|
|
for _, fpath in ipairs(dir.getfiles(
|
|
|
- path.join(MODEL_PATH, "typedef"), "*.lua")) do
|
|
|
+ path.join(MODEL_PATH, "schema"), "*.lua")) do
|
|
|
local mname = path.basename(fpath):gsub(".lua$", "")
|
|
|
- local typedef = parse_model(mname)
|
|
|
+ M.types[mname] = true
|
|
|
+ end
|
|
|
+ -- Add core schemata that were not extended by user config.
|
|
|
+ for _, fpath in ipairs(
|
|
|
+ dir.getfiles(datafile.path("core_schema"), "*.lua"
|
|
|
+ )) do
|
|
|
+ local mname = path.basename(fpath):gsub(".lua$", "")
|
|
|
+ M.types[mname] = true
|
|
|
+ end
|
|
|
+
|
|
|
+ for mname in pairs(M.types) do
|
|
|
+ local schema = parse_model(mname)
|
|
|
|
|
|
- -- Store parsed typedef configurations.
|
|
|
- M.types[mname] = typedef
|
|
|
+ -- Store parsed schema configurations.
|
|
|
+ M.types[mname] = schema
|
|
|
|
|
|
-- Store unique prop names.
|
|
|
- for pn in pairs(typedef.properties or NT) do
|
|
|
+ for pn in pairs(schema.properties or NT) do
|
|
|
if not no_ll_pnames[pn] then all_pnames[pn] = true end
|
|
|
end
|
|
|
end
|