cortav  Diff

Differences From Artifact [a9857f9cb6]:

To Artifact [ad6ab18d31]:


     3      3   
     4      4   local default_mode = {
     5      5   	['render:format'] = 'html';
     6      6   	['html:gen-styles'] = true;
     7      7   }
     8      8   
     9      9   local function
    10         -main(input, output, log, mode, suggestions, vars)
    11         -	local doc = ct.parse(input.stream, input.src, mode)
           10  +main(input, output, log, mode, suggestions, vars, extrule)
           11  +	local doc = ct.parse(input.stream, input.src, mode, function(c)
           12  +		                     c.doc.ext = extrule
           13  +	                     end)
    12     14   	input.stream:close()
    13     15   	if mode['parse:show-tree'] then
    14     16   		log:write(ss.dump(doc))
    15     17   	end
    16     18   
    17     19   	-- the document has now had a chance to give its say; if it hasn't specified
    18     20   	-- any modes of its own, we now merge in the 'weak modes' (suggestions)
................................................................................
    70     72   			['mode-set'] = 1;
    71     73   			['mode-clear'] = 1;
    72     74   			mode = 2;
    73     75   
    74     76   			['mode-set-weak'] = 1;
    75     77   			['mode-clear-weak'] = 1;
    76     78   			['mode-weak'] = 2;
           79  +			['use'] = 1;
           80  +			['inhibit'] = 1;
           81  +			['need'] = 1;
           82  +			['load'] = 1;
           83  +			['enc'] = 1;
    77     84   		}
    78     85   		return param_opts[o] or 0
    79     86   	end
    80     87   
    81     88   	local optmap = {
    82     89   		o = 'out';
    83     90   		l = 'log';
    84     91   		d = 'define';
    85     92   		V = 'version';
    86     93   		h = 'help';
    87     94   		y = 'mode-set',   Y = 'mode-set-weak';
    88     95   		n = 'mode-clear', N = 'mode-clear-weak';
    89     96   		m = 'mode',       M = 'mode-weak';
           97  +		L = 'load',
           98  +		u = 'use', i = 'inhibit', r = 'require';
           99  +		e = 'enc';
    90    100   	}
          101  +
          102  +	local extrule = {use={},inhibit={},need={}}
    91    103   
    92    104   	local checkmodekey = function(key)
    93    105   		if not key:match '[^:]+:.+' then
    94    106   			ct.exns.cli('invalid mode key %s', key):throw()
    95    107   		end
    96    108   		return key
    97    109   	end
................................................................................
   117    129   		mode = function(key,value) mode[checkmodekey(key)] = value end;
   118    130   		['mode-set'] = function(key) mode[checkmodekey(key)] = true end;
   119    131   		['mode-clear'] = function(key) mode[checkmodekey(key)] = false end;
   120    132   
   121    133   		['mode-weak'] = function(key,value) suggestions[checkmodekey(key)] = value end;
   122    134   		['mode-set-weak'] = function(key) suggestions[checkmodekey(key)] = true end;
   123    135   		['mode-clear-weak'] = function(key) suggestions[checkmodekey(key)] = false end;
   124         -
          136  +		['use'    ] = function(ext) extrule.use    [ext] = true end;
          137  +		['inhibit'] = function(ext) extrule.inhibit[ext] = true end;
          138  +		['require'] = function(ext) extrule.need   [ext] = true end;
          139  +		['load'] = function(extpath) end;
          140  +		['enc'] = function(enc) end;
   125    141   		['version'] = function()
   126    142   			outp:write(ct.info:about())
   127    143   			if next(ct.ext.loaded) then
   128    144   				outp:write('\nactive extensions:\n')
   129    145   				for k,v in pairs(ct.ext.loaded) do
   130    146   					outp:write(string.format(' * %s', v.id ..
   131    147   						(v.version and (' ' .. v.version:string()) or '')))
................................................................................
   175    191   			keepParsing = false
   176    192   		else
   177    193   			local longopt = v:match '^%-%-(.+)$'
   178    194   			if keepParsing and longopt then
   179    195   				execLongOpt(longopt)
   180    196   			else
   181    197   				if keepParsing and v:sub(1,1) == '-' then
   182         -					for c,p in ss.str.enc.utf8.each(v:sub(2)) do
          198  +					for c,p in ss.str.each(ss.str.enc.utf8, v:sub(2)) do
   183    199   						if optmap[c] then
   184    200   							execLongOpt(optmap[c])
   185    201   						else
   186    202   							ct.exns.cli('switch -%s unrecognized', c):throw()
   187    203   						end
   188    204   					end
   189    205   				else
................................................................................
   197    213   	if args[1] and args[1] ~= '' then
   198    214   		local file = io.open(args[1], "rb")
   199    215   		if not file then error('unable to load file ' .. args[1]) end
   200    216   		input.stream = file
   201    217   		input.src.file = args[1]
   202    218   	end
   203    219   
   204         -	return main(input, outp, log, mode, suggestions, vars)
          220  +	return main(input, outp, log, mode, suggestions, vars, extrule)
   205    221   end
   206    222   
   207         -local ok, e = pcall(entry_cli)
   208         --- local ok, e = true, entry_cli()
          223  +-- local ok, e = pcall(entry_cli)
          224  +local ok, e = true, entry_cli()
   209    225   if not ok then
   210    226   	local str = 'translation failure'
   211    227   	if ss.exn.is(e) then
   212    228   		str = e.kind.desc
   213    229   	end
   214    230   	local color = false
   215    231   	if log:seek() == nil then