Skip to content

regexp/syntax: make Op implement fmt.Stringer #22684

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

Closed
ghost opened this issue Nov 13, 2017 · 7 comments
Closed

regexp/syntax: make Op implement fmt.Stringer #22684

ghost opened this issue Nov 13, 2017 · 7 comments

Comments

@ghost
Copy link

ghost commented Nov 13, 2017

The Op type doesn't have a String() method, and when you print it, it's just an obscure integer. It would be helpful if it was displayed as OpNoMatch, OpEmptyMatch, OpLiteral etc.

@gopherbot gopherbot added this to the Proposal milestone Nov 13, 2017
@rsc
Copy link
Contributor

rsc commented Nov 13, 2017

Sure, go ahead.

@rsc
Copy link
Contributor

rsc commented Nov 13, 2017

CL welcome for Go 1.11.

@rsc rsc modified the milestones: Proposal, Go1.11 Nov 13, 2017
@rsc rsc changed the title proposal: regexp/syntax: make Op implement fmt.Stringer regexp/syntax: make Op implement fmt.Stringer Nov 13, 2017
@mvdan
Copy link
Member

mvdan commented Nov 13, 2017

@rsc note that using stringer (the tool) in regexp/syntax might be problematic - was doing something similar in https://go-review.googlesource.com/c/go/+/77253.

What would the best solution here be? Not using the tool, making the package depend on fmt (likely not), or making stringer use strconv instead of fmt?

@ghost
Copy link
Author

ghost commented Nov 14, 2017

@mvdan

making the package depend on fmt (likely not), or making stringer use strconv instead of fmt?

Since Op is just uint8, it can be converted to a string without either fmt or strconv (and without allocations, too):
https://play.golang.org/p/iDrD8ecBjO

@mvdan
Copy link
Member

mvdan commented Nov 17, 2017

@opennota I think it is overkill for either regexp/syntax or stringer to worry about such micro-optimizations. Even better, strconv already does this for you - see the small stuff in https://golang.org/src/strconv/itoa.go?s=764:804#L13.

I changed stringer to use strconv earlier this week, so this change will be trivial to do in 1.11. I'll be doing other stringer improvements (like the already mailed https://go-review.googlesource.com/c/go/+/77253), so I can take this if you'd like.

@ghost
Copy link
Author

ghost commented Nov 18, 2017

@mvdan

I can take this if you'd like

By all means.

@mvdan mvdan self-assigned this Nov 18, 2017
@gopherbot
Copy link
Contributor

Change https://golang.org/cl/95355 mentions this issue: regexp/syntax: make Op an fmt.Stringer

@golang golang locked and limited conversation to collaborators Feb 20, 2019
@rsc rsc unassigned mvdan Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants