[comp.emacs] matching comments, balanced bracketing chars, etc

chris@mimsy.UUCP (Chris Torek) (02/02/88)

In article <143@axcess.UUCP> allbery@axcess.UUCP (Brandon S. Allbery) writes:
>... to teach Emacs about a standard way of handling paired strings.
>A list "matched-string-list" could be used to define these:
>
>(("{" "}" t) ("(" ")" t) ("/*" "*/" nil) ("[" "]" t) ("\"" "\"" nil))
>
>The list is made up of lists of (open-string, close-string, nest-flag).  The
>nest-flag is "t" if the balanced strings can balance with themselves and with
>other balancing strings; "nil" means the strings don't balance with themselves
>and Emacs should balance other strings only within the current pair of strings
>(i.e. a parenthesis inside a comment or string should never try to balance a
>parenthesis outside the comment or string).

This is not quite sufficient:  For instance, some languages allow
nested comments; nonetheless, these do not balance with other balancing
constructs.  That is, given a language where `{}' delimit comments,
the string

	a(b { ) { [) } } );

contains exactly one matching set of ()s.

I think it could work if you made the sublists contain two flags,
or (better) have each sublist include the other lists that it does
(or, perhaps, does not) match (either suffices; which is better
would take more thought).  Perhaps even more generally, allow
matches to invoke `gobble' functions: then nothing would stop you
(although anything might slow you down! :-) ).

Incidentally, some comment structures are such that only
`forward-looking' scans can recognise them.  In particular,
comment-to-end-of-line can be discovered only by looking forward
from the beginning of a line, not by looking backward from the end:

	; this is commented out even though there is another ; on the line
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@mimsy.umd.edu	Path:	uunet!mimsy!chris