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

Distinguish between /regexp/ and "regexp" in stringified output #222

Merged
merged 4 commits into from
Feb 28, 2024
Merged

Distinguish between /regexp/ and "regexp" in stringified output #222

merged 4 commits into from
Feb 28, 2024

Conversation

ypdn
Copy link
Contributor

@ypdn ypdn commented Feb 28, 2024

Fixes issue #221

Copy link
Owner

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Nice -- this is a very simple and tidy fix! I hadn't thought of that approach.

Just a couple of nit suggestions, and can we please add a test? You should be able to just add a line or two to the existing TestParseAndString test in parser_test.go.

Comment on lines 303 to 304
r := &RegExpr{e.Value}
return r.String()
Copy link
Owner

Choose a reason for hiding this comment

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

Nit suggestion (untested, but I think it should work):

Suggested change
r := &RegExpr{e.Value}
return r.String()
return RegExpr.String(e.Value)

Copy link
Contributor Author

@ypdn ypdn Feb 28, 2024

Choose a reason for hiding this comment

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

It won't, because (*RegExpr).String takes a *RegExpr as an argument, not a string.

Copy link
Owner

Choose a reason for hiding this comment

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

Ah yes, you're right.

Copy link
Owner

Choose a reason for hiding this comment

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

Building a RegExpr object here still feels a little weird -- can we factor out the content of RegExpr.String into formatRegex and call it from both places?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah

type StrExpr struct {
Value string
Value string
Regexp bool
Copy link
Owner

Choose a reason for hiding this comment

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

Naming nit: can we call this IsRegexp for clarity?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We could, but that's so not-Go

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe we should document it better?

Copy link
Owner

Choose a reason for hiding this comment

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

Looks like your mostly right that it's "not Go", though not entirely, for example, the Is* fields here. However, we have another bool in this package, IncrExpr.Pre, that doesn't have the Is, so let's go with that.

However, on closer look, can we please call it Regex bool? The "regexp" with a 'p' kind of refers to Go's "regexp" package, whereas we I tend to call it "regex" in an AWK context (for example, the RegExpr.Regex field itself).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Copy link
Owner

@benhoyt benhoyt left a comment

Choose a reason for hiding this comment

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

Nice, thanks for the contribution!

@benhoyt benhoyt changed the title Distinguish between /regexp/ and "regexp" Distinguish between /regexp/ and "regexp" in stringified output Feb 28, 2024
@benhoyt benhoyt merged commit 4ae6290 into benhoyt:master Feb 28, 2024
10 checks passed
@ypdn
Copy link
Contributor Author

ypdn commented Feb 28, 2024

@benhoyt Could you create a new tag so that go get would download it?

Keep in mind that this change breaks code that has an expression like ast.StrExpr{v} in it.

@benhoyt
Copy link
Owner

benhoyt commented Feb 28, 2024

That's okay: 1) the ast package is in internal so it can't be used outside of this repo, and 2) Go package compatibility usually doesn't guarantee that will continue working -- see "struct literals" in https://go.dev/doc/go1compat

@benhoyt
Copy link
Owner

benhoyt commented Feb 28, 2024

New version released: https://github.com/benhoyt/goawk/releases/tag/v1.26.0

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

Successfully merging this pull request may close these issues.

2 participants