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

overhaul regexp package #130

Closed
wants to merge 2 commits into from
Closed

overhaul regexp package #130

wants to merge 2 commits into from

Conversation

b5
Copy link
Member

@b5 b5 commented Oct 1, 2021

I'd like to harmonize our API around what's coming down the pipe for starlark/lib, but google/starlark-go#369 has been open since April, so let's shim this in until it's merged

closes #91

@b5 b5 added docs feat breaking change changes that affect the API labels Oct 1, 2021
@b5 b5 requested a review from dustmop October 1, 2021 02:04
@b5 b5 self-assigned this Oct 1, 2021
@b5 b5 changed the title B5/fix regexp overhaul regexp package Oct 1, 2021
Copy link
Contributor

@dustmop dustmop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have some comments, but pretty sure I know the answers already. Approved.

regexp/regexp.go Outdated

// Converts the replacement pattern to make it compatible with what the regexp package expects.
func convertReplacementPattern(repl string) string {
// Escapes the specifal dollar characters if any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

specifal -> special

// Converts the replacement pattern to make it compatible with what the regexp package expects.
func convertReplacementPattern(repl string) string {
// Escapes the specifal dollar characters if any
repl = strings.ReplaceAll(repl, "$", "$$")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this always work? I think it's over-zealous, and would break this example:

import re
s = 'big$money'
re.match(r'[\w]+\$[\w]+', s)

Rewriting a regex to work with a different syntax probably requires fully parsing it, not just single character replacement. Of course, it's a bit of an edge case, and if we're ok with losing correctness until the upstream version is done, it's probably not too big of a problem.

func (r *Regexp) AttrNames() []string { return builtinAttrNames(regexMethods) }

var regexMethods = map[string]*starlark.Builtin{
"find": starlark.NewBuiltin("find", find),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A big question we keep coming back to: how much do we want to be just like python? The more our library can be a drop-in replacement for python, the easier it will be for users to get comfortable with starlark. In particular, I always use the match method in python, as most docs and tutorials reference it early on. Should we be implementing that as well?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we should have this chat before merging a breaking change like this. Let's leave this PR in limbo for the moment

this code is a shim while we work to merge the old re library (no heavily modified) upstream into starlark/lib

BREAKING CHANGE:
re is deprecated in favour of new regexp package
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change changes that affect the API docs feat
Projects
None yet
Development

Successfully merging this pull request may close these issues.

re
2 participants