-
-
Notifications
You must be signed in to change notification settings - Fork 85
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
Conversation
There was a problem hiding this 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
.
internal/ast/ast.go
Outdated
r := &RegExpr{e.Value} | ||
return r.String() |
There was a problem hiding this comment.
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):
r := &RegExpr{e.Value} | |
return r.String() | |
return RegExpr.String(e.Value) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah
internal/ast/ast.go
Outdated
type StrExpr struct { | ||
Value string | ||
Value string | ||
Regexp bool |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this 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 Could you create a new tag so that Keep in mind that this change breaks code that has an expression like |
That's okay: 1) the |
New version released: https://github.com/benhoyt/goawk/releases/tag/v1.26.0 |
Fixes issue #221