Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

regexp/syntax: panic: unhandled case in compile - x{2} #68067

Closed
bogdan-deac opened this issue Jun 19, 2024 · 1 comment
Closed

regexp/syntax: panic: unhandled case in compile - x{2} #68067

bogdan-deac opened this issue Jun 19, 2024 · 1 comment

Comments

@bogdan-deac
Copy link

bogdan-deac commented Jun 19, 2024

Go version

go version go1.22.2 darwin/arm64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/Users/bdeac/Library/Caches/go-build'
GOENV='/Users/bdeac/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/bdeac/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/bdeac/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/opt/homebrew/Cellar/go/1.22.2/libexec'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/opt/homebrew/Cellar/go/1.22.2/libexec/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.22.2'
GCCGO='gccgo'
AR='ar'
CC='cc'
CXX='c++'
CGO_ENABLED='1'
GOMOD='/Users/bdeac/Documents/learning/regex/go.mod'
GOWORK=''
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
PKG_CONFIG='pkg-config'
GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/fd/pkkd278j26g5q23_wwwj38bh0000gq/T/go-build4036665068=/tmp/go-build -gno-record-gcc-switches -fno-common

What did you do?

import (
	"errors"
	"fmt"
	"regexp/syntax"
)

func main() {
        regex := "x{2}"
        regParse, err := syntax.Parse(regex, 0)
	if err != nil {
		return errors.New(fmt.Sprintf("issue parsing regex %s: %s ", regex, err.Error()))
	}

	regParse.Simplify()

	prog, err := syntax.Compile(regParse)
	if err != nil {
		return errors.New(fmt.Sprintf("issue compiling regex %s: %s ", regex, err.Error()))
	}

        fmt.Println(len(prog.Inst))
}

What did you see happen?

panic: regexp: unhandled case in compile

This appears to be because OpRepeat (17) is not handled here. I based my implementation on this suggestion.

Furthermore, using something like regexp.MustCompile causes no issue for x{2} .

What did you expect to see?

Successful Compilation

I'm not sure if this is intended behaviour and there's an alternative way to accomplish this, but I would think at the very least the documentation of syntax.Compile should include a possible panic.

@bogdan-deac bogdan-deac changed the title regexp/syntax: panic: unhandled case in compile - OpRepeat (17) regexp/syntax: panic: unhandled case in compile - x{2} Jun 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants