parsav  Diff

Differences From Artifact [3e776df34f]:

To Artifact [ba911a8ebc]:


     1      1   -- vim: ft=terra
     2      2   -- string template generator:
     3      3   -- returns a function that fills out a template
     4      4   -- with the strings given
     5      5   
     6         -local util = dofile 'common.lua'
            6  +local util = lib.util
     7      7   local m = {}
     8      8   function m.mk(tplspec)
     9      9   	local str
    10     10   	if type(tplspec) == 'string'
    11     11   		then str = tplspec tplspec = {}
    12     12   		else str = tplspec.body
    13     13   	end
................................................................................
    21     21   	tplchar_o = string.gsub(tplchar_o,'%%','%%%%')
    22     22   	tplchar = string.gsub(tplchar, '.', function(c)
    23     23   		if magic[c] then return '%' .. c end
    24     24   	end)
    25     25   	local last = 1
    26     26   	local fields = {}
    27     27   	local segs = {}
           28  +	local docs = {}
    28     29   	local constlen = 0
    29     30   	-- strip out all irrelevant whitespace to tidy things up
    30     31   	-- TODO: find way to exclude <pre> tags?
    31     32   	str = str:gsub('[\n^]%s+','')
    32     33   	str = str:gsub('%s+[\n$]','')
    33     34   	str = str:gsub('\n','')
    34     35   	str = str:gsub('</a><a ','</a> <a ') -- keep nav links from getting smooshed
           36  +	str = str:gsub(tplchar .. '%?([-%w]+)', function(file)
           37  +		if not docs[file] then docs[file] = data.doc[file] end
           38  +		return string.format('<a href="#help-%s" class="help">?</a>', file)
           39  +	end)
    35     40   	for start, key, stop in string.gmatch(str,'()'..tplchar..'(%w+)()') do
    36     41   		if string.sub(str,start-1,start-1) ~= '\\' then
    37     42   			segs[#segs+1] = string.sub(str,last,start-1)
    38     43   			fields[#segs] = key
    39     44   			last = stop
    40     45   		end
    41     46   	end
    42     47   	segs[#segs+1] = string.sub(str,last)
           48  +
    43     49   	for i, s in ipairs(segs) do
    44     50   		segs[i] = string.gsub(s, '\\'..tplchar, tplchar_o)
    45     51   		constlen = constlen + string.len(segs[i])
    46     52   	end
           53  +
           54  +	for n,d in pairs(docs) do
           55  +		local html = string.format(
           56  +			'<div id="help-%s" class="modal"> <a href="#0">close</a> <div>%s</div></div>', n, d.text
           57  +		)
           58  +		segs[#segs] = segs[#segs] .. html
           59  +		constlen = constlen + #html
           60  +	end
           61  +	
    47     62   
    48     63   	local runningtally = symbol(intptr)
    49     64   	local tallyup = {quote
    50     65   		var [runningtally] = 1 + constlen
    51     66   	end}
    52     67   	local rec = terralib.types.newstruct(string.format('template<%s>',tplspec.id or ''))
    53     68   	local symself = symbol(&rec)