parsav  Diff

Differences From Artifact [ce74a1083d]:

To Artifact [2f4ebceee0]:


34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
65
66
67
68
69
70
71


72
73
74
75
76
77

78
79
80
81


82

83
84
85
86

87




88

89
90
91
92
93
94
95
...
102
103
104
105
106
107
108

109
110
111











112
113


114
115

116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
	str = str:gsub('%s+[\n$]','')
	str = str:gsub('\n','')
	str = str:gsub('</a><a ','</a> <a ') -- keep nav links from getting smooshed
	str = str:gsub(tplchar .. '%?([-%w]+)', function(file)
		if not docs[file] then docs[file] = data.doc[file] end
		return string.format('<a href="#help-%s" class="help">?</a>', file)
	end)
	for start, mode, key, stop in string.gmatch(str,'()'..tplchar..'([:!$]?)([-a-zA-Z0-9_]+)()') do
		if string.sub(str,start-1,start-1) ~= '\\' then
			segs[#segs+1] = string.sub(str,last,start-1)
			fields[#segs] = { key = key:gsub('-','_'), mode = (mode ~= '' and mode or nil) }
			last = stop
		end
	end
	segs[#segs+1] = string.sub(str,last)
................................................................................
	local tallyup = {quote
		var [runningtally] = 1 + constlen
	end}
	local rec = terralib.types.newstruct(string.format('template<%s>',tplspec.id or ''))
	local symself = symbol(&rec)
	do local kfac = {}
		local sanmode = {}


		for afterseg,fld in ipairs(fields) do
			if not kfac[fld.key] then
				rec.entries[#rec.entries + 1] = {
					field = fld.key;
					type = lib.mem.ptr(int8);
				}

			end
			kfac[fld.key] = (kfac[fld.key] or 0) + 1
			sanmode[fld.key] = fld.mode == ':' and 6
				or fld.mode == '!' and 5


				or fld.mode == '$' and 2 or 1

		end
		for key, fac in pairs(kfac) do
			local sanfac = sanmode[key]
			

			tallyup[#tallyup + 1] = quote




				[runningtally] = [runningtally] + ([symself].[key].ct)*fac*sanfac

			end
		end
	end

	local copiers = {}
	local senders = {}
	local appenders = {}
................................................................................
		copiers[#copiers+1] = quote [cpypos] = lib.mem.cpy([cpypos], [&opaque]([seg]), [#seg]) end
		senders[#senders+1] = quote lib.net.mg_send([destcon], [seg], [#seg]) end
		appenders[#appenders+1] = quote [accumulator]:push([seg], [#seg]) end
		if fields[idx] and fields[idx].mode then
			local f = fields[idx]
			local fp = `symself.[f.key]
			local sanexp

			if f.mode == '$' then
				sanexp = `lib.str.qesc(pool, fp)
			else











				sanexp = `lib.html.sanitize(pool, fp, [f.mode == ':'])
			end


			copiers[#copiers+1] = quote 
				if fp.ct > 0 then

					var san = sanexp
					[cpypos] = lib.mem.cpy([cpypos], [&opaque](san.ptr), san.ct)
					--san:free()
				end
			end
			senders[#senders+1] = quote
				if fp.ct > 0 then
					var san = sanexp
					lib.net.mg_send([destcon], san.ptr, san.ct)
					--san:free()
				end
			end
			appenders[#appenders+1] = quote
				if fp.ct > 0 then
					var san = sanexp
					[accumulator]:ppush(san)
					--san:free()
				end
			end
		elseif fields[idx] then
			local f = fields[idx]







|







 







>
>




|

>




>
>
|
>



<
>
|
>
>
>
>
|
>







 







>
|
|
<
>
>
>
>
>
>
>
>
>
>
>
|
<
>
>

<
>






|






|







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
..
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
113
114
115
116
117
118
119
120
121
122

123
124
125
126
127
128
129
130
131
132
133
134

135
136
137

138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
	str = str:gsub('%s+[\n$]','')
	str = str:gsub('\n','')
	str = str:gsub('</a><a ','</a> <a ') -- keep nav links from getting smooshed
	str = str:gsub(tplchar .. '%?([-%w]+)', function(file)
		if not docs[file] then docs[file] = data.doc[file] end
		return string.format('<a href="#help-%s" class="help">?</a>', file)
	end)
	for start, mode, key, stop in string.gmatch(str,'()'..tplchar..'([+:!$#%^]?)([-a-zA-Z0-9_]+)()') do
		if string.sub(str,start-1,start-1) ~= '\\' then
			segs[#segs+1] = string.sub(str,last,start-1)
			fields[#segs] = { key = key:gsub('-','_'), mode = (mode ~= '' and mode or nil) }
			last = stop
		end
	end
	segs[#segs+1] = string.sub(str,last)
................................................................................
	local tallyup = {quote
		var [runningtally] = 1 + constlen
	end}
	local rec = terralib.types.newstruct(string.format('template<%s>',tplspec.id or ''))
	local symself = symbol(&rec)
	do local kfac = {}
		local sanmode = {}
		local types = { ['^'] = uint64, ['#'] = uint64 }
		local recmap = {}
		for afterseg,fld in ipairs(fields) do
			if not kfac[fld.key] then
				rec.entries[#rec.entries + 1] = {
					field = fld.key;
					type = types[fld.mode] or pstr;
				}
				recmap[fld.key] = rec.entries[#rec.entries]
			end
			kfac[fld.key] = (kfac[fld.key] or 0) + 1
			sanmode[fld.key] = fld.mode == ':' and 6
				or fld.mode == '!' and 5
				or (fld.mode == '$' or fld.mode == '+') and 2
				or fld.mode == '^' and lib.math.shorthand.maxlen
				or fld.mode == '#' and 20
				or 1
		end
		for key, fac in pairs(kfac) do
			local sanfac = sanmode[key]

			if recmap[key].type ~= pstr then
				tallyup[#tallyup + 1] = quote
					[runningtally] = [runningtally] + fac*sanfac
				end
			else
				tallyup[#tallyup + 1] = quote
					[runningtally] = [runningtally] + ([symself].[key].ct)*fac*sanfac
				end
			end
		end
	end

	local copiers = {}
	local senders = {}
	local appenders = {}
................................................................................
		copiers[#copiers+1] = quote [cpypos] = lib.mem.cpy([cpypos], [&opaque]([seg]), [#seg]) end
		senders[#senders+1] = quote lib.net.mg_send([destcon], [seg], [#seg]) end
		appenders[#appenders+1] = quote [accumulator]:push([seg], [#seg]) end
		if fields[idx] and fields[idx].mode then
			local f = fields[idx]
			local fp = `symself.[f.key]
			local sanexp
			local nulexp
			if f.mode == '$' then sanexp = `lib.str.qesc(pool, fp, true)
			elseif f.mode == '+' then sanexp = `lib.str.qesc(pool, fp, false)

			elseif f.mode == '#' then
				sanexp = quote
					var ibuf: int8[21]
					var ptr = lib.math.decstr(fp, &ibuf[20])
				in pstr {ptr=ptr, ct=&ibuf[20] - ptr} end
			elseif f.mode == '^' then

				sanexp = quote
					var shbuf: lib.math.shorthand.t
					var len = lib.math.shorthand.gen(fp, &shbuf[0])
				in pstr {ptr=&shbuf[0],ct=len} end
			else sanexp = `lib.html.sanitize(pool, fp, [f.mode == ':']) end

			if f.mode == '^' or f.mode == '#' then nulexp = `true
			else nulexp = `fp.ct > 0 end
			copiers[#copiers+1] = quote 

				if [nulexp] then
					var san = sanexp
					[cpypos] = lib.mem.cpy([cpypos], [&opaque](san.ptr), san.ct)
					--san:free()
				end
			end
			senders[#senders+1] = quote
				if [nulexp] then
					var san = sanexp
					lib.net.mg_send([destcon], san.ptr, san.ct)
					--san:free()
				end
			end
			appenders[#appenders+1] = quote
				if [nulexp] then
					var san = sanexp
					[accumulator]:ppush(san)
					--san:free()
				end
			end
		elseif fields[idx] then
			local f = fields[idx]