From 696f85d96a15672b810a4ffe2e45fe9ebf14aff6 Mon Sep 17 00:00:00 2001 From: John Kerl Date: Sun, 8 Aug 2021 13:29:44 -0400 Subject: [PATCH] Accept some now-passing regex cases --- .../dsl-filter-pattern-action/0015/cmd | 0 .../dsl-filter-pattern-action/0015/experr | 0 .../dsl-filter-pattern-action/0015/expout | 0 .../dsl-filter-pattern-action/0016/cmd | 0 .../dsl-filter-pattern-action/0016/experr | 0 .../dsl-filter-pattern-action/0016/expout | 0 .../dsl-filter-pattern-action/0017/cmd | 0 .../dsl-filter-pattern-action/0017/experr | 0 .../dsl-filter-pattern-action/0017/expout | 0 .../dsl-filter-pattern-action/0023/cmd | 0 .../dsl-filter-pattern-action/0023/experr | 0 .../dsl-filter-pattern-action/0023/expout | 0 .../dsl-filter-pattern-action/0075/cmd | 0 .../dsl-filter-pattern-action/0075/experr | 0 .../dsl-filter-pattern-action/0075/expout | 0 .../dsl-filter-pattern-action/0075/input | 0 .../dsl-filter-pattern-action/0076/cmd | 0 .../dsl-filter-pattern-action/0076/experr | 0 .../dsl-filter-pattern-action/0076/expout | 0 .../dsl-filter-pattern-action/0076/input | 0 go/src/lib/regex.go | 55 ++++++------------- 21 files changed, 16 insertions(+), 39 deletions(-) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0015/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0015/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0015/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0016/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0016/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0016/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0017/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0017/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0017/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0023/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0023/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0023/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0075/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0075/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0075/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0075/input (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0076/cmd (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0076/experr (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0076/expout (100%) rename go/regtest/{cases-pending-go-port => cases}/dsl-filter-pattern-action/0076/input (100%) diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/cmd b/go/regtest/cases/dsl-filter-pattern-action/0015/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0015/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/experr b/go/regtest/cases/dsl-filter-pattern-action/0015/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/experr rename to go/regtest/cases/dsl-filter-pattern-action/0015/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/expout b/go/regtest/cases/dsl-filter-pattern-action/0015/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0015/expout rename to go/regtest/cases/dsl-filter-pattern-action/0015/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/cmd b/go/regtest/cases/dsl-filter-pattern-action/0016/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0016/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/experr b/go/regtest/cases/dsl-filter-pattern-action/0016/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/experr rename to go/regtest/cases/dsl-filter-pattern-action/0016/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/expout b/go/regtest/cases/dsl-filter-pattern-action/0016/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0016/expout rename to go/regtest/cases/dsl-filter-pattern-action/0016/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/cmd b/go/regtest/cases/dsl-filter-pattern-action/0017/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0017/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/experr b/go/regtest/cases/dsl-filter-pattern-action/0017/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/experr rename to go/regtest/cases/dsl-filter-pattern-action/0017/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/expout b/go/regtest/cases/dsl-filter-pattern-action/0017/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0017/expout rename to go/regtest/cases/dsl-filter-pattern-action/0017/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/cmd b/go/regtest/cases/dsl-filter-pattern-action/0023/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0023/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/experr b/go/regtest/cases/dsl-filter-pattern-action/0023/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/experr rename to go/regtest/cases/dsl-filter-pattern-action/0023/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/expout b/go/regtest/cases/dsl-filter-pattern-action/0023/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0023/expout rename to go/regtest/cases/dsl-filter-pattern-action/0023/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/cmd b/go/regtest/cases/dsl-filter-pattern-action/0075/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0075/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/experr b/go/regtest/cases/dsl-filter-pattern-action/0075/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/experr rename to go/regtest/cases/dsl-filter-pattern-action/0075/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/expout b/go/regtest/cases/dsl-filter-pattern-action/0075/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/expout rename to go/regtest/cases/dsl-filter-pattern-action/0075/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/input b/go/regtest/cases/dsl-filter-pattern-action/0075/input similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0075/input rename to go/regtest/cases/dsl-filter-pattern-action/0075/input diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/cmd b/go/regtest/cases/dsl-filter-pattern-action/0076/cmd similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/cmd rename to go/regtest/cases/dsl-filter-pattern-action/0076/cmd diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/experr b/go/regtest/cases/dsl-filter-pattern-action/0076/experr similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/experr rename to go/regtest/cases/dsl-filter-pattern-action/0076/experr diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/expout b/go/regtest/cases/dsl-filter-pattern-action/0076/expout similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/expout rename to go/regtest/cases/dsl-filter-pattern-action/0076/expout diff --git a/go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/input b/go/regtest/cases/dsl-filter-pattern-action/0076/input similarity index 100% rename from go/regtest/cases-pending-go-port/dsl-filter-pattern-action/0076/input rename to go/regtest/cases/dsl-filter-pattern-action/0076/input diff --git a/go/src/lib/regex.go b/go/src/lib/regex.go index 0f6cc348b..6a510941d 100644 --- a/go/src/lib/regex.go +++ b/go/src/lib/regex.go @@ -1,3 +1,5 @@ +// xxx update comment + package lib // TODO: @@ -6,23 +8,6 @@ package lib // o UTs for that // * flesh out RegexCaptureBinaryFunctionCallsiteNode to do that -// xxx update comment - -// The key is the Go library's regex.FindAllStringIndex. It gives us start -// (inclusive) and end (exclusive) indices for matches. -// -// Example: for pattern "foo" and input "abc foo def foo ghi" we'll have -// matrix [[4 7] [12 15]] which indicates matches from positions 4-6 and -// 12-14. We simply need to concatenate -// * 0-3 "abc " not matching -// * 4-6 "foo" matching -// * 7-11 " def " not matching -// * 12-14 "foo" matching -// * 15-18 " ghi" not matching -// -// Example: with pattern "f.*o" and input "abc foo def foo ghi" we'll have -// matrix [[4 15]] so "foo def foo" will be a matched substring. - import ( "bytes" "fmt" @@ -88,6 +73,7 @@ func CompileMillerRegexOrDie(regexString string) *regexp.Regexp { // xxx MakeEmptyCaptures function for CST state // xxx ReplacementHasCaptures function +// xxx ReplacementMatrixExtractor ... // RegexSubWithoutCaptures implements the sub DSL function when the replacement // string has none of "\1".."\9". @@ -97,12 +83,12 @@ func RegexSubWithoutCaptures( replacement string, ) string { regex := CompileMillerRegexOrDie(sregex) - // to do return RegexSubWithoutCapturesCompiled(input, regex, replacement) } // RegexSubWithoutCapturesCompiled is the same as RegexSubWithoutCaptures but -// with compiled regex instead of regex-as-string. +// with compiled regex instead of regex-as-string. This is a simple use of +// the Go regexp library. func RegexSubWithoutCapturesCompiled( input string, regex *regexp.Regexp, @@ -140,8 +126,9 @@ func RegexSubCompiledWithCaptures( return regexSubGsubWithCapturesAux(input, regex, replacement, true) } -// RegexGsubWithoutCaptures implements the gsub DSL function when the replacement -// string has none of "\1".."\9". +// RegexGsubWithoutCaptures implements the gsub DSL function when the +// replacement string has none of "\1".."\9". This is a simple use of the Go +// regexp library. func RegexGsubWithoutCaptures( input string, sregex string, @@ -179,7 +166,13 @@ func RegexGsubWithCaptures( // and the =~ callsite doesn't know if captures will be used or not. So, // RegexMatches always returns the captures array. It is stored within the CST // state. -func RegexMatches(input string, sregex string) (matches bool, capturesOneUp []string) { +func RegexMatches( + input string, + sregex string, +) ( + matches bool, + capturesOneUp []string, +) { regex := CompileMillerRegexOrDie(sregex) return regexMatchesAux(input, regex) } @@ -187,18 +180,6 @@ func RegexMatches(input string, sregex string) (matches bool, capturesOneUp []st // ---------------------------------------------------------------- // Package-internal/implementation functions -// xxx: -// $ go run foo.go "ab_cde ab_cde" "(ab)_(cde)" -// MATRIX [][]int{[]int{0, 6, 0, 2, 3, 6}, []int{8, 14, 8, 10, 11, 14}} -// 0 6 "ab_cde" -// n:6 -// 2 0 2 "ab" -// 4 3 6 "cde" -// 8 14 "ab_cde" -// n:6 -// 2 8 10 "ab" -// 4 11 14 "cde" - // regexSubGsubWithCapturesAux is the implementation for sub/gsub when the // replacement string uses captures in the form "\1".."\9". func regexSubGsubWithCapturesAux( @@ -265,7 +246,6 @@ func regexSubGsubWithCapturesAux( // "..." -> "..." // "fg_hij" -> "hij:fg" --- and here // "..." -> "..." - // interpolateCaptures( replacement, // TODO: move to caller where it can be precomputed and stored @@ -361,10 +341,7 @@ func regexMatchesAux( // * 6-9 is for the second capture "cde" di := 1 - for si := 2; si < n; si += 2 { - if di > 9 { - break - } + for si := 2; si < n && di <= 9; si += 2 { start := row[si] end := row[si+1] captures[di] = input[start:end]