Cobra Interactive Query Language pattern set management


ps -- pattern set management


	ps create name
	ps convert name
	ps delete name
	ps list  [name]
	ps name = name [& | ^ + -} name


A named pattern set can be created with the pe command, or it can be created by converting an existing set of token markings into a structured and named pattern set with the create option, as follows:
	: ps create Setname
This command leaves the exising markings in tact, but stores a copy as a named set where it can later be combined with other sets or have its elements displayed separately with a dp command.

The reverse operation, converting a set of structured matches into basic markings while leaving the set unmodified is performed by the convert option.

	: ps convert name
The list option lists the available sets (or a specific one) together with the number of patterns that each set contains.

The delete option omits the named set.

The ps command can also be used to create new derived sets by applying standard set operations to other named sets. There are three such commands, to define set union, difference, or intersection. In this form the first name given is to be followed (after a space) by an assignment operator (=) and two existing setnames separated by an operator.

	: ps C = A & B
Defines a new set C that contains the intersection of existing sets A and B (i.e., only those elements that appear in both sets).
	: ps C = A | B
or alternatively
	: ps C = A + B
Defines a new set C that contains the union of A and B.
	: ps C = A ^ B
or alternatively
	: ps C = A - B
Defines a new set C that contains the elements of A that do not also appear in named set B.


  $ cobra *.c	# cobra sources
  : pe A: for ( x:@ident .* ) { .* :x = .* }
  9 patterns stored in set 'A'
  : dp A 1	# display first pattern matched
  : pe B: for ( .* ) { .* emalloc .* }
  7 patterns stored in set 'B'
  : dp B 1	# display first pattern matched
   : ps C = A & B  	# set intersection
   : ps D = A + B  	# set union
   : ps E = A - B  	# set difference
   : ps F = B - A
   : ps convert F	# convert the patterns in set C to markings


pattern searches, dp, ps, pe/pat,

Return to index
(Last Updated: 12 September 2021)