Cobra Interactive Query Language comments/source

NAME

comments / source — switch between the comments and the source token sequence

SYNTAX

	comments	# analyze comments -- version 4.0 and later
	source		# analyze source code -- version 4.0 and later

DESCRIPTION

Starting with Cobra version 4.0, comments (which technically count as white-space) are separated from the main program token stream. To search comment tokens, the command comments can be used, and to switch back the command source is used, as in:
	$ cobra *.[ch]
	...
	: comments
	: r; m /\;		# find comments with semi-colons in them
	: d			# display them
	: r; m (.len > 20)	# find comments longer than 20 characters
	: d			# display them
	: source		# switch back to the main source tokens
	...
	: q
	$
When preprocessing is used (command-line option -cpp) all comments will be removed from the token stream by the preprocessor, so the comments stream will be empty. There is however a way to both analyze preprocessed code and to retain the token stream separately, as follows:
	$ cobra *.[ch]	# start without preprocessing, which creates the token sequence
	...
	: cpp on	# now enable preprocessing, which replaces only the main sequence
	: comments	# and comments are preserved
	...
The .bound field of all tokens is set to point to the lexical token that immediately followed a comment token in the original token sequence. This could of course be another comment, but it can help to correlate the main source text with comments if needed. For instance, if we want to see if a comment is immediately followed by a null-statement:
	: comments
	: %{	q = .bound;
		if (q.seq > 0
		&&  q.txt == ";")
		{	print q.fnm ":" q.lnr ": comment precedes null-statement\n";
		}
	  %}
	: source

SEE ALSO

Version 4.0 update notes.

Return to index
Manual
Tutorial
(Last Updated: 10 May 2022)