cortav  Check-in [0042f47e35]

Overview
Comment:fix definition-form deref rendering, fix exns, add debug mechanism for printing stacktraces, alleviate multifarious dimbulbery
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | trunk
Files: files | file ages | folders
SHA3-256: 0042f47e35e38a5eef62c89daf189c9231e361050debd05f3c0a6e2bd4066ca5
User & Date: lexi on 2024-07-18 21:43:59
Other Links: manifest | tags
Context
2024-07-18
21:43
fix definition-form deref rendering, fix exns, add debug mechanism for printing stacktraces, alleviate multifarious dimbulbery Leaf check-in: 0042f47e35 user: lexi tags: trunk
18:36
fix untransmogrified footnotes begot by absent hook call check-in: bb010e612e user: lexi tags: trunk
Changes

Modified cli.lua from [0dc68c1657] to [047ac156ff].

   222    222   		input.stream = file
   223    223   		input.src.file = args[1]
   224    224   	end
   225    225   
   226    226   	return main(input, outp, log, mode, suggestions, vars, extrule)
   227    227   end
   228    228   
   229         --- local ok, e = pcall(entry_cli)
   230         -local ok, e = true, entry_cli()
          229  +local ok, e = xpcall(entry_cli, function(e)
          230  +	if not ss.exn.is(e) then
          231  +		e = ss.bug('lua vm error: %s', e)
          232  +	end
          233  +	e.trace = debug.traceback(nil, nil, 1)
          234  +	log:write(e.trace .. '\n')
          235  +	return e
          236  +end)
          237  +-- local ok, e = true, entry_cli()
   231    238   if not ok then
   232    239   	local str = 'translation failure'
   233    240   	if ss.exn.is(e) then
   234    241   		str = e.kind.desc
   235    242   	end
   236    243   	local color = false
   237    244   	if native then
................................................................................
   250    257   			end
   251    258   		end
   252    259   	end
   253    260   	if color then
   254    261   		str = string.format('\27[1;31m%s\27[m', str)
   255    262   	end
   256    263   	log:write(string.format('%s: %s\n', str, e))
          264  +	if ss._debug and ss.exn.is(e) and e.trace then
          265  +		log:write(e.trace)
          266  +	end
   257    267   	os.exit(1)
   258    268   end
   259    269   os.exit(e)

Modified cortav.lua from [3e270c2a7b] to [f2a5ec5d52].

     1      1   -- [ʞ] cortav.lua
     2      2   --  ~ lexi hale <lexi@hale.su>
     3      3   --  © EUPL v1.2
     4      4   --  ? reference implementation of the cortav document language
            5  +--  \ from Ranuir "written document"
     5      6   --
     6      7   --  ! TODO refactor encoding logic. it's a complete
     7      8   --         mess and i seem to have repeatedly gotten
     8      9   --         confused about how it's supposed to work.
     9     10   --         the whole shitshow needs to be replaced
    10     11   --         with a clean, simple paradigm: documents
    11     12   --         are translated to UTF8 on the way in, and
................................................................................
   116    117   			new.generation = old.generation + 1
   117    118   		else
   118    119   			new.generation = 1
   119    120   		end
   120    121   	end;
   121    122   	fns = {
   122    123   		fail = function(self, msg, ...)
   123         -			--error(string.format(msg,...))
          124  +			-- error(string.format(msg,...))
   124    125   			ct.exns.tx(msg, self.src.file, self.line or 0, ...):throw()
   125    126   		end;
   126    127   		insert = function(self, block)
   127    128   			block.origin = self:clone()
   128    129   			table.insert(self.sec.blocks,block)
   129    130   			return block
   130    131   		end;
................................................................................
   358    359   		end;
   359    360   		job = function(self, name, pred, ...) -- convenience func
   360    361   			return self.docjob:fork(name, pred, ...)
   361    362   		end;
   362    363   		sub = function(self, ctx)
   363    364   			-- convenience function for single-inheritance structure
   364    365   			-- sets up a doc/ctx pair for a subdocument embedded in the source
   365         -			-- of a gretaer document, pointing subdoc props to global tables/values
          366  +			-- of a greater document, pointing subdoc props to global tables/values
   366    367   			local newdoc = ct.doc.mk(self)
   367    368   			newdoc.meta = self.meta
   368    369   			newdoc.ext = self.ext
   369    370   			newdoc.enc = self.enc
   370    371   			newdoc.stage = self.stage
   371    372   			newdoc.defined_in_parent_section = ctx.sec
   372    373   			-- vars are handled through proper recursion across all parents and

Modified makefile from [8d3e37cc0b] to [c76cdbdd22].

    85     85   	cat $< >>$@
    86     86   	chmod +x $@
    87     87   
    88     88   # raw bytecode without shebang header, must be run as `lua cortav.lc`
    89     89   $(build)/$(executable).lc: sirsem.lua $(encoding-files) cortav.lua $(rendrs) $(extens) cli.lua | $(build)/
    90     90   	@echo ' » building with extensions $(extens-names)'
    91     91   	@echo ' » building with renderers $(rendrs-names)'
    92         -	$(call comp-lua,$^,$@)
           92  +	$(if $(debug),echo "require'sirsem'._debug=1" | $(call comp-lua,sirsem.lua - $(filter-out sirsem.lua,$^),$@),$(call comp-lua,$^,$@))
    93     93   
    94     94   # true standalone binary, wraps bytecode file and (optionally) lua
    95     95   $(build)/$(executable).bin: $(build)/$(executable).lc tool/makeshim.lua $(binds)
    96     96   	$(lua) tool/makeshim.lua $< "" $(binds-names) |\
    97     97   		$(CC) -s -o$@ -xc - -xnone $(binds) $(lua-standalone) $(lua-bindeps)
    98     98   
    99     99   # loadable lua modules for binds, mainly useful for testing
................................................................................
   104    104   	$(build)/$(executable) $< -o $@ -m render:format html -y html:fossil-uv
   105    105   
   106    106   .PHONY: syncdoc
   107    107   syncdoc: $(build)/cortav.html
   108    108   	fossil uv add $< --as cortav.html
   109    109   	fossil uv sync --all
   110    110   
   111         -# clean is written in overly cautious fashion to minimize damage,
   112         -# just in case it ever gets invoked in a bad way (e.g. build=/)
          111  +# clean and wipe are written in overly cautious fashion to minimize damage,
          112  +# just in case they ever get invoked in a bad way (e.g. build=/)
   113    113   .PHONY: clean
   114    114   clean:
   115         -	rm -f $(build)/*.{html,lc,sh,txt,desktop} \
   116         -	      $(build)/$(executable){,.bin} \
   117         -	      $(build)/bind
          115  +	rm -f $(build)/*.{html,lc,sh,desktop} \
          116  +	      $(build)/$(executable){,.bin}
          117  +	rm -r $(build)/bind
          118  +# wipe also kills external datasheets
          119  +.PHONY: wipe
          120  +wipe: clean
          121  +	rm -f $(build)/*.txt
   118    122   	rmdir $(build)
   119    123   
   120    124   $(build)/%.sh: desk/%.sh | $(build)/
   121    125   	echo >$@ "#!$(sh)"
   122    126   	echo >>$@ 'cortav_exec="$(bin-prefix)/$(executable)"'
   123    127   	echo >>$@ 'cortav_flags="$${ct_format_flags-$(default-format-flags)}"'
   124    128   	cat $< >> $@

Modified render/html.lua from [e178fd542c] to [7d5a564158].

   737    737   			-- return string.format("&#%u;", code)
   738    738   		end
   739    739   
   740    740   		function span_renderers.deref(t,b,s)
   741    741   			local r = b.origin:ref(t.ref)
   742    742   			local name = t.ref
   743    743   			if name:find'%.' then name = name:match '^[^.]*%.(.+)$' end
          744  +
   744    745   			if type(r) == 'string' then
   745    746   				addStyle 'abbr'
   746         -				return tag('abbr',{title=r},next(t.spans) and htmlSpan(t.spans,b,s) or name)
          747  +				r = ct.parse_span(r, b.origin)
          748  +				return tag('abbr',{title=htmlentities(plainrdr.htmlSpan(r))}, next(t.spans) and htmlSpan(t.spans,b,s) or name)
   747    749   			end
   748    750   			if r.kind == 'resource' then
   749    751   				local rid = getSafeID(r, 'res-')
   750    752   				if r.class == 'image' then
   751    753   					if not cssRulesFor[r] then
   752    754   						local css = prepcss(string.format([[
   753    755   							section p > .%s {

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


Modified tool/makeshim.lua from [9df833faa8] to [c724b89ab4].