cortav  Check-in [84b6c875fb]

Overview
Comment:"fix" macro bullshit
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 84b6c875fb1e61e1abeef0b4338e9e1cfb52b577b9fb4b5923a70cda5695155f
User & Date: lexi on 2022-09-30 18:57:32
Other Links: manifest | tags
Context
2022-09-30
20:15
let the flayings commence check-in: 89a6dd28ef user: lexi tags: trunk
18:57
"fix" macro bullshit check-in: 84b6c875fb user: lexi tags: trunk
2022-09-14
12:22
various improvements check-in: dd5c3bfcb9 user: lexi tags: trunk
Changes

Modified cortav.lua from [2184d83e7b] to [ea1fbe20dd].

449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
...
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
...
754
755
756
757
758
759
760

761
762
763
764
765
766
767
768
769
770
771


772
773
774
775
776
777
778
779
780
781
782
783
784
785
786

787


788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
	fns = {
		fork = function(me, name, pred, ...)
			-- generate a branch job linked to this job
			local branch = getmetatable(me)(name, me.doc, pred, ...)
			branch.parent = me
			return branch
		end;
		delegate = function(me, ext) -- creates a delegate for state access
			local submethods = {
				unwind = function(self, n)
					local function
					climb(dlg, job, n)
						if n == 0 then
							return job:delegate(dlg.extension)
						else
................................................................................
					return D.target[key]
				end;
				__newindex = function(self, key, value)
					local D = self._delegate_state
					if key == 'state' then
						D.target.states[D.extension] = value
					else
						D.target[D.extension] = value
					end
				end;
			});
			return d;
		end;
		each = function(me, ...)
			local ek
			local path = {...}
			return function()
				while true do
					ek = next(me.states, ek)
................................................................................
-- objects, including ones that users have not assigned IDs
-- to, and objects with the same name in different unlabeled
-- sections. to handle this, we provide a "namespace" mechanism,
-- where some lua table (really its address in memory) is used
-- as a handle for the object and a unique ID is attached to it.
-- if the object has an ID of its own, it is guaranteed to be
-- unique and returned; otherwise, a generic id of the form
-- `x-%u` is generated, where %u is an integer that increments
-- for every new object
	local ids = {}
	local canonicalID = {}
	return function(obj,pfx)
		pfx = pfx or ''
		if canonicalID[obj] then
			return canonicalID[obj]
................................................................................
			code = cp;
		}
	end
	ct.spanctls = {
		{seq = '!', parse = formatter 'emph'};
		{seq = '*', parse = formatter 'strong'};
		{seq = '~', parse = formatter 'strike'};

		{seq = '+', parse = formatter 'insert'};
		{seq = '\\', parse = function(s, c) -- raw
			return {
				kind = 'raw';
				spans = {s};
				origin = c:clone();
			}
		end};
		{seq = '`', parse = formatter 'literal'};
		{seq = '"', parse = rawcode};
		{seq = '$', parse = formatter 'variable'};


		{seq = '^', parse = function(s, c)
		-- TODO support for footnote sections
			local fn, t = s:match '^([^%s]+)%s*(.-)$'
			return {
				kind = 'footnote';
				spans = (t and t~='') and ct.parse_span(t, c) or {};
				ref = fn;
				origin = c:clone();
			}
		end};
		{seq = '=', parse = function(s,c) --math mode
			local tx = {
				['%*'] = '×';
				['/'] = '÷';
			}

			for k,v in pairs(tx) do s = s:gsub(k,v) end


			s=s:gsub('%^([0-9]+)', function(num)
				local sup = {'⁰','¹','²','³','⁴','⁵','⁶','⁷','⁸','⁹'};
				local r = ''
				for i=1,#num do
					r = r .. sup[1 + (num:byte(i) - 0x30)]
				end
				return r
			end)
			local m = {s} --TODO
			return {
				kind = 'math';
				original = s;
				spans = {s};
				origin = c:clone();
			};







|







 







|


|
|







 







|







 







>











>
>











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







449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
...
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
...
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
...
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788

789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
	fns = {
		fork = function(me, name, pred, ...)
			-- generate a branch job linked to this job
			local branch = getmetatable(me)(name, me.doc, pred, ...)
			branch.parent = me
			return branch
		end;
		delegate = function(me, ext) -- creates a delegate for hierarchical state access
			local submethods = {
				unwind = function(self, n)
					local function
					climb(dlg, job, n)
						if n == 0 then
							return job:delegate(dlg.extension)
						else
................................................................................
					return D.target[key]
				end;
				__newindex = function(self, key, value)
					local D = self._delegate_state
					if key == 'state' then
						D.target.states[D.extension] = value
					else
						D.target[D.extension] = value -- FIXME?? is this right???
					end
				end;
			})
			return d
		end;
		each = function(me, ...)
			local ek
			local path = {...}
			return function()
				while true do
					ek = next(me.states, ek)
................................................................................
-- objects, including ones that users have not assigned IDs
-- to, and objects with the same name in different unlabeled
-- sections. to handle this, we provide a "namespace" mechanism,
-- where some lua table (really its address in memory) is used
-- as a handle for the object and a unique ID is attached to it.
-- if the object has an ID of its own, it is guaranteed to be
-- unique and returned; otherwise, a generic id of the form
-- `x-%u` is generated, where %u is an integer that incrementsfile:///home/lexi/dev/cortav/build/cortav.html
-- for every new object
	local ids = {}
	local canonicalID = {}
	return function(obj,pfx)
		pfx = pfx or ''
		if canonicalID[obj] then
			return canonicalID[obj]
................................................................................
			code = cp;
		}
	end
	ct.spanctls = {
		{seq = '!', parse = formatter 'emph'};
		{seq = '*', parse = formatter 'strong'};
		{seq = '~', parse = formatter 'strike'};
		{seq = '_', parse = formatter 'underline'};
		{seq = '+', parse = formatter 'insert'};
		{seq = '\\', parse = function(s, c) -- raw
			return {
				kind = 'raw';
				spans = {s};
				origin = c:clone();
			}
		end};
		{seq = '`', parse = formatter 'literal'};
		{seq = '"', parse = rawcode};
		{seq = '$', parse = formatter 'variable'};
		{seq = "'", parse = formatter 'super'};
		{seq = ',', parse = formatter 'sub'};
		{seq = '^', parse = function(s, c)
		-- TODO support for footnote sections
			local fn, t = s:match '^([^%s]+)%s*(.-)$'
			return {
				kind = 'footnote';
				spans = (t and t~='') and ct.parse_span(t, c) or {};
				ref = fn;
				origin = c:clone();
			}
		end};
		{seq = '=', parse = function(s,c) --math mode
			if c.doc.enc ~= ss.str.enc.ascii then
				for _,v in pairs(ss.compseq.math) do
					local seq, utf8, html, cp = table.unpack(v)

					seq = seq:gsub('[-+.*?[%]%%]', '%%%0') -- >_<
					s = s:gsub(seq,c.doc.enc.encodeUCS(utf8))
				end
			end
-- 			s=s:gsub('%^([0-9]+)', function(num)
-- 				local sup = {'⁰','¹','²','³','⁴','⁵','⁶','⁷','⁸','⁹'};
-- 				local r = ''
-- 				for i=1,#num do
-- 					r = r .. sup[1 + (num:byte(i) - 0x30)]
-- 				end
-- 				return r
-- 			end)
			local m = {s} --TODO
			return {
				kind = 'math';
				original = s;
				spans = {s};
				origin = c:clone();
			};

Modified ext/transmogrify.lua from [ad59e4c740] to [b92020d7d8].

20
21
22
23
24
25
26


27
28
29
30
31
32
33
...
138
139
140
141
142
143
144



145
146
147
148
149
150
151
			['<->'] = '↔';
			['-->'] = '→';
			['<--'] = '←';
			['==>'] = '⇒';
			['<=>'] = '⇔';
			['<=='] = '⇐';
			['=/='] = '≠';


			['---'] = '⸺';
		};

		{
			['-:-'] = '÷';
			['--'] = '—';
			['(C)'] = '©';
................................................................................
ct.ext.install {
	id = 'transmogrify';
	version = ss.version {0,1; 'devel'};
	contributors = {{name='lexi hale', handle='velartrill', mail='lexi@hale.su', homepage='https://hale.su'}};
	default = true; -- on unless inhibited
	slow = true;
	hook = {



		doc_meddle_ast = function(job)
			for n, sec in pairs(job.doc.secorder) do
				if sec.kind=='ordinary' or sec.kind=='quote'
				or sec.kind=='footnote' then
					for i, block in pairs(sec.blocks) do
			         if type(block.spans) == 'table' then
							enterspan(block.origin, block.spans)







>
>







 







>
>
>







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
			['<->'] = '↔';
			['-->'] = '→';
			['<--'] = '←';
			['==>'] = '⇒';
			['<=>'] = '⇔';
			['<=='] = '⇐';
			['=/='] = '≠';
			['::='] = '⩴';
			[':='] = '≔';
			['---'] = '⸺';
		};

		{
			['-:-'] = '÷';
			['--'] = '—';
			['(C)'] = '©';
................................................................................
ct.ext.install {
	id = 'transmogrify';
	version = ss.version {0,1; 'devel'};
	contributors = {{name='lexi hale', handle='velartrill', mail='lexi@hale.su', homepage='https://hale.su'}};
	default = true; -- on unless inhibited
	slow = true;
	hook = {
		doc_macro_expand_span = function(job, ir, block)
			enterspan(block.origin, ir)
		end;
		doc_meddle_ast = function(job)
			for n, sec in pairs(job.doc.secorder) do
				if sec.kind=='ordinary' or sec.kind=='quote'
				or sec.kind=='footnote' then
					for i, block in pairs(sec.blocks) do
			         if type(block.spans) == 'table' then
							enterspan(block.origin, block.spans)

Modified render/groff.lua from [810c155515] to [729b875cf0].

392
393
394
395
396
397
398







399
400
401
402
403
404
405
406

		local r = b.origin:ref(macroname)
		if type(r) ~= 'string' then
			b.origin:fail('%s is an object, not a reference', t.ref)
		end
		local mctx = b.origin:clone()
		      mctx.invocation = m







		rs.renderSpans(rc, ct.parse_span(r, mctx))
	end

	function rs.renderSpans(rc, sp, b, sec)
		rc = rc or mkrc(b.origin)
		for i, v in ipairs(sp) do
			if type(v) == 'string' then
				rc:span(v)







>
>
>
>
>
>
>
|







392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413

		local r = b.origin:ref(macroname)
		if type(r) ~= 'string' then
			b.origin:fail('%s is an object, not a reference', t.ref)
		end
		local mctx = b.origin:clone()
		      mctx.invocation = m

		local ir = ct.parse_span(r, mctx)
		local j = b.origin.doc.docjob
		for fn, ext, state in j:each('hook', 'doc_macro_expand_span') do
			local r = fn(j:delegate(ext), ir, b)
			if r then ir = r end
		end
		rs.renderSpans(rc, ir)
	end

	function rs.renderSpans(rc, sp, b, sec)
		rc = rc or mkrc(b.origin)
		for i, v in ipairs(sp) do
			if type(v) == 'string' then
				rc:span(v)

Modified render/html.lua from [f4ce452531] to [05c1f2d6b4].

684
685
686
687
688
689
690
691










692
693
694
695
696
697
698
...
764
765
766
767
768
769
770
771








772
773
774
775
776
777
778
	local function getSpanRenderers(procs)
		local tag, elt, catenate = procs.tag, procs.elt, procs.catenate
		local span_renderers = {}
		local plainrdr = getBaseRenderers(tagproc.toTXT, span_renderers)
		local htmlSpan = getBaseRenderers(procs, span_renderers).htmlSpan

		function span_renderers.format(sp,...)
			local tags = { strong = 'strong', emph = 'em', strike = 'del', insert = 'ins', literal = 'code', variable = 'var'}










			if sp.style == 'literal' and not opts['fossil-uv'] then
				addStyle 'code'
			elseif sp.style == 'strike' or sp.style == 'insert' then
				addStyle 'editors_markup'
			elseif sp.style == 'variable' then
				addStyle 'var'
			end
................................................................................
				ct.parse_span(m.macro, b.origin), b,s)
			local r = b.origin:ref(macroname)
			if type(r) ~= 'string' then
				b.origin:fail('%s is an object, not a reference', r.id)
			end
			local mctx = b.origin:clone()
			mctx.invocation = m
			return htmlSpan(ct.parse_span(r, mctx),b,s)








		end
		function span_renderers.math(m,b,s)
			addStyle 'math'
			local spans = {}
			local function fmt(sp, target)
				for i,v in ipairs(sp) do
					if type(v) == 'string' then







|
>
>
>
>
>
>
>
>
>
>







 







|
>
>
>
>
>
>
>
>







684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
...
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
	local function getSpanRenderers(procs)
		local tag, elt, catenate = procs.tag, procs.elt, procs.catenate
		local span_renderers = {}
		local plainrdr = getBaseRenderers(tagproc.toTXT, span_renderers)
		local htmlSpan = getBaseRenderers(procs, span_renderers).htmlSpan

		function span_renderers.format(sp,...)
			local tags = {
				strong = 'strong';
				emph = 'em';
				strike = 'del';
				insert = 'ins';
				literal = 'code';
				variable = 'var';
				super = 'sup';
				sub = 'sub';
				underline = 'u';
			}
			if sp.style == 'literal' and not opts['fossil-uv'] then
				addStyle 'code'
			elseif sp.style == 'strike' or sp.style == 'insert' then
				addStyle 'editors_markup'
			elseif sp.style == 'variable' then
				addStyle 'var'
			end
................................................................................
				ct.parse_span(m.macro, b.origin), b,s)
			local r = b.origin:ref(macroname)
			if type(r) ~= 'string' then
				b.origin:fail('%s is an object, not a reference', r.id)
			end
			local mctx = b.origin:clone()
			mctx.invocation = m
			local ir = ct.parse_span(r, mctx)
			-- even though this happens at render time, it really shouldn't;
			-- we pretend this is happening as part of the document job
			local j = b.origin.doc.docjob
			for fn, ext, state in j:each('hook', 'doc_macro_expand_span') do
				local r = fn(j:delegate(ext), ir, b)
				if r then ir = r end
			end
			return htmlSpan(ir, b, s)
		end
		function span_renderers.math(m,b,s)
			addStyle 'math'
			local spans = {}
			local function fmt(sp, target)
				for i,v in ipairs(sp) do
					if type(v) == 'string' then

Modified sirsem.lua from [c72ad0a8fc] to [7e67a3ff12].

1639
1640
1641
1642
1643
1644
1645










































				end
			end
			return c == pc
		end;
	};
}
ss.mime.exn = ss.exnkind 'MIME error'

















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
				end
			end
			return c == pc
		end;
	};
}
ss.mime.exn = ss.exnkind 'MIME error'


-- a composition table maps from a compose sequence to the tuple
-- {UTF8, htmlentity, UCS codepoint}
ss.compseq = {
	math = {
		{'*', '×', 'times', 0x2A2F};
		{'/', '÷', 'divide', 0x00F7};
		{'-', '−', 'minus', 0x2212};
		{'+-', '±', 'plusmn', 0x00B1};
		{'&&', '∧', 'and', 0x2227};
		{'||', '∨', 'or', 0x2228};
		{'&', '⋏', nil, 0x22CF};
		{'|', '⋎', nil, 0x22CE};
		{'~', '¬', 'not', 0x00AC};
		{'~=', '≠', 'ne', 0x2260};
		{'^=', '≜', 'trie', 0x225C};
		{':=', '≔', 'coloneq', 0x2254};
		{'::=', '⩴', nil, 0x2A74};
		{'==', '≡', 'equiv', 0x2261};
		{'===', '≣', nil, 0x2263};
		{'<=', '≤', 'le', 0x2264};
		{'>=', '≥', 'ge', 0x2265};
		{'?=', '≟', 'questeq', 0x225F};
		{'@<', '∝', 'prop', 0x221D};
		{'<>', '⋄', nil, 0x22C4};
		{'~~', '≈', 'asymp', 0x2248};
		{'<==>', '⟺', 'Longleftrightarrow', 0x27FA};
		{'<=>', '⇔', 'hArr', 0x21D4};
		{'==>', '⟹', 'DoubleLongRightArrow', 0x27F9};
		{'=>', '⇒', 'rArr', 0x21D2};
		{'<->', '↔', 'harr', 0x2194};
		{'->', '→', 'rarr', 0x2192};
		{'<-', '←', 'ShortLeftArrow', 0x2190};
		{'~|', '⊕', 'oplus', 0x2295};
		{'@A', '∀', 'forall', 0x2200};
		{'~@E', '∄', 'NotExists', 0x2204};
		{'@E', '∃', 'exist', 0x2203};
		{'.*.', '∴', 'therefore', 0x2234};
		{'*.*', '∵', 'because', 0x2235};
	};
};