util  rich-ascii.ct at [0894d03fbf]

File spec/rich-ascii.ct artifact 67dad5f4d3 part of check-in 0894d03fbf


# rich ascii
[*rich ascii] is a file format that adds very basic organizational and structural data to a text file using only ASCII control codes. even though it is called [*rich ascii], it is fully compatible with UTF-8.

##s document structure
	def: : [*[#1]] ::= [#2]
	ctl: [#1][,[#2]]
	ref: [U+27E8][*[#1]][U+27E9]
%% nested macro ident interpolation is currently broken; it seems to always use the arguments of the top(?)-level invocation, so we have to use this ugly fucking hack instead. fuck me
	SOH: {ctl [&q-SOH SOH]|1}
	STX: {ctl [&q-STX STX]|2}
	ETX: {ctl [&q-ETX ETX]|3}
	HT: {ctl [&q-HT HT]|9}
	NL: {ctl [&q-NL NL]|10}
	FF: {ctl [&q-FF FF]|12}
	DLE: {ctl [&q-DLE DLE]|16}

	q-SOH: start of heading
	q-STX: start of text
	q-ETX: end of text
	q-FF: form feed
	q-HT: horizontal tab
	q-NL: newline
	q-DLE: data link escape

a rich ascii document consists of a series of UTF-8 or ASCII codepoints.

$def doc|{ref title} {ref block}*
$def title|{SOH} {ref span} {ETX}
$def block|{SOH} {ref span} {STX} {ref body} {ETX}
$def block|{STX} {ref body} {ETX}
$def block|{ref table-row}
$def block|{ref metadata}
$def table-row|{ref table-cell}*
$def table-cell|{HT}+ {STX} {ref span} {ETX}
$def table-cell|{HT}+ {SOH} {ref span} {ETX}
$def metadata|{DLE} {ref text} {STX} {ref body} {ETX}
$def text|[!(any valid sequence of ASCII or UTF-8 characters of codepoint [=0x20] or higher)]
$def span|{ref text}
$def body|{ref span}*
$def body|{ref block}*

here is a structurally annotated document with several levels of headings.

> {SOH} worldgov expropriation notice {ETX}
> {s.DLE} author {s.STX} eudavia wobblebotch, esq. {s.ETX}
> {s.STX} please read this missive with the utmost care and attention to detail. failure to comply may result in liquidation without prior notice. {s.ETX}
> {s.SOH} demands {s.STX}
>> {s.STX} you are by the splendid munificence of EUDAVIA MILLWEED WOBBLEBOTCH, ESQ. hereby ordered, commanded, and impelled to collect posthaste the following objects, thought processes, bureaucratic minutia, and/or thumotic residuals, immediately thereupon to deliver them to the WORLDGOV OFFICE OF REQUISITIONS, IMPOSITIONS, & INQUISITIONS. failure to comply may result in liquidation without prior notice.
>> {s.SOH} carapace of a WALLOWING SLIMETOOTLER {s.STX}
>>> {s.STX} easily located by application of a rigorously dour pataphor when dawns the witching hour {s.ETX}
>>> {s.SOH} mandatory qualia {s.STX}
>>>> {STX} pulchritude {ETX}
>>> {s.ETX}
>> {s.ETX}
>> {s.SOH} verse of cultivation {s.STX}
>>> woe on thee, unit {NL}
>>> of fungible labor {NL}
>>> your productivity {NL}
>>> has diminished {NL}
>>> and your soul {NL}
>>> has been requisitioned {NL}
>>> by THE SMILING MAN {NL}
>>> for Project {NL}
>>> Scowling Lizard.
>> {s.ETX}
> {s.ETX}