Files
mercury/extras/lex/tests/cmp_regex_gawk
Mark Brown d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00

77 lines
1.6 KiB
Awk
Executable File

#! /usr/bin/gawk -f
#
# Copyright (C) 2002 The University of Melbourne
# Copyright (C) 2018 The Mercury team.
# This file is distributed under the terms specified in COPYING.LIB.
# This is a gawk program that attempts to mirror what test_regex does
# for global search and replace. It scans the files test_regex.in
# and test_regex.exp and tests for differences between the results
# obtained by gawk and those obtained by regex. It exits with a non-zero
# return code if any differences are detected.
BEGIN {
IN = "test_regex.in"
EXP = "test_regex.exp"
regex = ""
while(getline lineIN < IN) {
if(lineIN ~ "set_regex") {
regexp = strip(lineIN)
}
else if(lineIN ~ "try_match") {
string = strip(lineIN)
gawk = string
gsub(regexp, "<&>", gawk)
while(getline lineEXP < EXP) {
if(lineEXP ~ "change_all") {
regex = strip(lineEXP)
if(regex != gawk) {
print "pattern \"" regexp "\""
print "string \"" string "\""
print "regex \"" regex "\""
print "gawk \"" gawk "\""
print ""
failed = 1
}
break
}
else if(lineEXP ~ "^all matches *: \\[\\]$") {
if(gawk != string) {
print "pattern \"" regexp "\""
print "string \"" string "\""
print "regex finds no match"
print "gawk \"" gawk "\""
print ""
failed = 1
}
while(getline lineEXP < EXP) {
if(lineEXP ~ "") { break }
}
break
}
}
}
}
exit failed
}
# Remove the outermost level of quotation from a string.
#
function strip(l) {
sub(/^[^\"]*\"/, "", l)
sub(/\"[^\"]*$/, "", l)
gsub(/\\\\/, "\\", l)
return l
}