Cobra Interactive Query Language patterns

NAME

patterns and regular expressions

SYNTAX

	p_expr: (expr)		|
		/regex

	expr:	( expr )        |
		expr binop expr |
		unop expr       |
		const_expr	|
		tokref		|
		name

	const_expr: size nr |
		nr

	regex:	[-^$\[\]a-zA-Z0-9_]+

	binop:	+  | -  | * | /  | %  |
		>  | >= | < | <= |
		== | != |
		&& | || | & | \|

	unop:	! | -

	tokref:	.bracket	# nesting level of square brackets
		.curly		# nesting level of curly braces
		.fct		# function name (or "global")
		.fnm		# filename
		.len		# length of the token text
		.lnr		# line number
		.mark		# current value of token mark
		.range		# length in lines of an associated range, or -1
		.round		# nesting level of parentheses
		.seq		# internal sequence nr of the token

	name	[a-bA-Z][a-zA-Z0-9_]+

DESCRIPTION

All Cobra commands that accept pattern arguments (e.g., mark, contains, extend, stretch, etc.) can take either a regular expression, or a pattern expression enclosed in round braces as an argument.
Regular expressions (starting with a single forward slash /) can be used only to match the text of a token.
The pattern expressions can refer to any predefined token attribute, other than just the token text or type.

EXAMPLES

	: m /.			# mark all tokens (using a regex that matches anything)
	: m & (.lnr > 10 && .lnr < 100)	# keep only those for source lines 10..100
	: reset
	: m @ident		# mark all identifiers
	: m & (.len > 32)	# keep only those longer than 32 characters
	: >2			# save marks in set 1
	: m & (size(2) > 100)	# preserve marks only if there are more than 100 marks in set 2
	: m & (.fnm == "cobra.h")  # can use either == or != for .fnm
	: m & (.fnm == /.h$)	# match only in filenames ending in .h (no quotes needed)
A typical use might be:
	: m \;			# select all statement separators
	: s \;			# attach a range from each mark upto the next statement separator
	: m & (.round == 0)	# exclude sequences inside (...), ie for-stmnts
	: m & (.range == 0)	# match only ranges on a single line
	: m & (.fnm == /^foo)	# and only for file-names that start with "foo"
More examples:
	: m & @str		# keep match only if the type is string
	: m & /^nfm		# keep match only if the text starts with nfm
	: m & (.fnm == /^nfm)	# keep match only for filenames starting with nfm
	: # there can only be one regular expression per constraint, so this works:
	: m & (.fnm == /^pref && .curly > 0)
	: # but this does not:
	: m & (.fnm == /^pref1 || .fnm == /^pref2 )

SEE ALSO

contains, extend, back, mark, next, stretch, with

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