Testsuite regular expression question

Andreas Schwab schwab@redhat.com
Tue Oct 27 17:13:00 GMT 2009


The regexp should not use .* in the first place, because "." also
matches the newline, and you need to use the non-capturing variant of
the grouping operator.

$ tclsh
% set fd [open "~/src/gcc/gcc/gcc/testsuite/gcc.dg/debug/dwarf2/inline2.s" r]
file3
% set text [read $fd]
[...]
% regexp -inline -all -- "byte.*?0x3.*? DW_AT_inline" $text
{byte	0x3	# Start new file
	.uleb128 0x0	# Included from line number 0
	.uleb128 0x1	# file inline2.c
	.byte	0x1	# Define macro
	.uleb128 0x0	# At line number 0
	.ascii "__STDC__ 1\0"	# The macro
	.byte	0x1	# Define macro
	.uleb128 0x0	# At line number 0
	.ascii "__STDC_HOSTED__ 1\0"	# The macro
	.byte	0x1	# Define macro
	.uleb128 0x0	# At line number 0
	.ascii "__GNUC__ 4\0"	# The macro
	.byte	0x1	# Define macro
	.uleb128 0x0	# At line number 0
[...]
% regexp -inline -all -- "byte\[^\n\]*0x3\[^\n\]* DW_AT_inline" $text
{byte	0x3	# DW_AT_inline} {byte	0x3	# DW_AT_inline} {byte	0x3	# DW_AT_inline}
% regexp -inline -all -- "(byte|data1)\[^\n\]*0x3\[^\n\]* DW_AT_inline" $text
{byte	0x3	# DW_AT_inline} byte {byte	0x3	# DW_AT_inline} byte {byte	0x3	# DW_AT_inline} byte
% regexp -inline -all -- "(?:byte|data1)\[^\n\]*0x3\[^\n\]* DW_AT_inline" $text
{byte	0x3	# DW_AT_inline} {byte	0x3	# DW_AT_inline} {byte	0x3	# DW_AT_inline}

Andreas.

-- 
Andreas Schwab, schwab@redhat.com
GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84  5EC7 45C6 250E 6F00 984E
"And now for something completely different."



More information about the Gcc mailing list