Differences From
Artifact [49893a127f]:
158 158 if not id:find'%.' then
159 159 if sec then
160 160 local rid = sec.refs[id]
161 161 if rid then
162 162 return rid, id, sec
163 163 end
164 164 end
165 +
166 + for _, i in ipairs(sec.imports) do
167 + local rr, ri, rs = checkFromSec(i, doc)
168 + if ri then return rr, ri, rs end
169 + end
165 170
166 171 if doc.sections[id] then
167 172 return nil, id, doc.sections[id]
168 173 end
174 +
175 + for _, i in ipairs(doc.globals) do
176 + local rr, ri, rs = checkFromSec(i, doc)
177 + if ri then return rr, ri, rs end
178 + end
169 179 else
170 180 local secid, ref = string.match(id, "(.-)%.(.+)")
171 181 local s
172 182 s = s or doc.sections[secid]
173 183 if s then
174 184 if s.refs[ref] then
175 185 return s.refs[ref], ref, s
................................................................................
221 231 }
222 232
223 233 ct.sec = declare {
224 234 ident = 'section';
225 235 mk = function() return {
226 236 blocks = {};
227 237 refs = {};
238 + imports = {};
228 239 depth = 0;
229 240 kind = 'ordinary';
230 241 } end;
231 242 construct = function(self, id, depth)
232 243 self.id = id
233 244 self.depth = depth or self.depth
234 245 end;
................................................................................
355 366 nctx.line = ctx.line
356 367 nctx.docDepth = (ctx.docDepth or 0) + ctx.sec.depth - 1
357 368 return newdoc, nctx
358 369 end;
359 370 };
360 371 mk = function(...) return {
361 372 sections = {};
373 + globals = {};
362 374 secorder = {};
363 375 embed = {};
364 376 meta = {};
365 377 vars = {};
366 378 parents = {...};
367 379 ext = {
368 380 inhibit = {};
................................................................................
1004 1016 ct.directives = {
1005 1017 author = dsetmeta;
1006 1018 license = dsetmeta;
1007 1019 keywords = dsetmeta;
1008 1020 desc = dsetmeta;
1009 1021 when = dcond;
1010 1022 unless = dcond;
1023 + with = function(w,c)
1024 + local _,str = w(2)
1025 + local aka, name = str:match '^([^=])=(.*)$'
1026 + if aka == nil then name=str aka=name end
1027 +
1028 + local o,id,s = c:ref(name)
1029 + if o then -- import object
1030 + c.sec.import.objs[aka] = o
1031 + else -- import scope
1032 + table.insert(c.sec.import.scope, s)
1033 + end
1034 + end;
1035 + global = function(w,c)
1036 + local _,str = w(2)
1037 + if str ~= nil and str ~= '' then
1038 + local aka, name = str:match '^([^=])=(.*)$'
1039 + if aka == nil then name=str aka=name end
1040 +
1041 + local o,id,s = c:ref(name)
1042 +
1043 + if o then
1044 + c.doc.globals.objs[aka] = name
1045 + else
1046 + table.insert(c.doc.globals, s)
1047 + end
1048 + else
1049 + table.insert(c.doc.globals, c.sec)
1050 + end
1051 + end;
1011 1052 pragma = function(w,c)
1012 1053 end;
1013 1054 lang = function(w,c)
1014 1055 local _, op, l = w(2)
1015 1056 local langstack = c.doc.stage.langstack
1016 1057 if op == 'is' then
1017 1058 langstack[math.max(1, #langstack)] = l