Friday, August 31, 2012

[cvervury] Cross referencing parentheses

Easily browse Lisp-like code on a printed page.

Every parenthesis is annotated with three numbers: its identifier, its match, and its up-list number.  The identifier number enumerates parentheses in ascending order of appearance: (1 (2 )3 )4.  The match number gives the matching parenthesis.  The up-list number gives the enclosing corresponding parenthesis, Emacs functions backward-up-list and up-list for open and close respectively.

Full example: (1m4u- (2m3u1 )3m2u4 )4m1u-.  Perhaps more compactly: (1,4 1(2,3 2,3)4 1,4) with the type encoded by position, mirror symmetry between open and close: u(i,m m,i)u.  Bigger example: (1,10 1(2,7 2(3,4 3,4)7 2(5,6 5,6)7 2,7)10 1(8,9 8,9)10 1,10).

A number may be truncated to a suffix if the prefix is noted at the beginning of the line.  This could become a typesetting challenge.

Maybe typeset numbers at different levels to help distinguish the different types: above, below, superscript, subscript.  Omit obvious numbers, like the backward-up-list for the second parenthesis of two open parentheses in a row.  Bigger example becomes: (1,10 (2,7 (3 4)7 2(5 6) 2,7)10 1(8 9) 1,10).  Could omit numbers that are not referenced: (1,10 (2,7 ( )7 2( ) 2,7)10 1( ) 1,10).  They remain invisibly numbered for ease of external references.

No comments :