Cobra Interactive Query Language def

NAME

def — define a named script

SYNTAX

	def scriptname[( parameters)]
	...
	end

DESCRIPTION

The format of a named script definition is as follows:
	def find_code_before_includes	# MISRA rule 20.1
		cpp off			# disable preprocessing
		m /^#include; b \;
	end
The keyword def introduces a new script, or redefines an existing one. The keyword must be followed by a name, and an optional list of parameters enclosed in round braces. No other commands can follow on the same line. Lines or parts of lines starting with whitespace followed by a # are comments. Note in the above example that the # character in #include is not preceded by whitespace (tabs or spaces) and therefore not considered a comment delimiter.

The line with the def keyword is followed by a series of cobra commands, which are usually indented, though this is not required. The script is concluded with a single keyword end on a line by itself.

EXAMPLES

Scripts can take arguments, as in:
	def find_assignments_to(fnm)	# one parameter
		m =
		b \;
		s =
		m ir /fnm
	end
	:find_assignments_to flist
This script first marks all assignment operators, then searches backwards from each assignment operator found to the end of the last statement. It then defines a range from that point forward to the assignment operator, and searches inside the resulting range for a specific identifier with a regular expression.

Formal parameters are replaced with actual parameters with simple string substitution, so be careful that formal parameter names do not match anything other than the parameters to be replaced. In the above example, for instance, it would be a bad idea to use parameters named s, m, b, or ir.

NOTES

A named script can contain any command sequence, and it can also contain inline programs.
	def name(param)
	%{
		...param
	%}
	end

SEE ALSO

def

Return to index
Manual
Tutorial
(Last Updated: 8 May 2017)