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

Fix #49 and #36 - use go scanner for parsing lines and identifiers #50

Merged
merged 3 commits into from
Aug 30, 2018

Conversation

justnoise
Copy link
Contributor

I ran into some issues of genny finding identifier boundaries. It seems that others have run into these issues as well:

The parser was updated to use go's golang scanner (go/scanner) to find identifier boundaries instead of splitting on whitespace and checking for characters at the alphanumeric boundaries.

@matryer
Copy link
Contributor

matryer commented Aug 16, 2018

@pdrum Can you review this please? It looks good to me.

parse/parse.go Outdated

// Does the heavy lifting of taking a line of our code and
// sbustituting a type into there for our generic type
func subTypeIntoLine(l, t, specificType string) string {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think maybe having line and type rather than l and t would make things a little more readable.

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, line(string) was another function in this file so I've renamed that to makeLine(string). type is a go keyword so I've hastily settled on the less-concise typeTemplate.

parse/parse.go Outdated
// the start or ends before the end of the literal
if i > 0 || i < len(lit)-len(t) {
// replace the literal with a capitalized version
cap := wordify(specificType, unicode.IsUpper(rune(lit[0])))
Copy link
Collaborator

Choose a reason for hiding this comment

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

For the comment preceding it to be true, shouldn't the parameter always be true? For example for someNumberType with NumberType=int I guess we want to have someInt. Doesn't it output someint as is? (I didn't run it, just asking)

parse/parse.go Outdated
@@ -40,6 +40,67 @@ var unwantedLinePrefixes = [][]byte{
[]byte("//go:generate genny "),
}

func subIntoLiteral(lit, t, specificType string) string {
var i int
var newLine string
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess now that you have extracted this piece into a function, this variable shouldn't be called newLine anymore. Maybe newLiteral or sth.

parse/parse.go Outdated
func subIntoLiteral(lit, t, specificType string) string {
var i int
var newLine string
for {
Copy link
Collaborator

@pdrum pdrum Aug 16, 2018

Choose a reason for hiding this comment

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

I think now that this function is just replacing the occurrences in a single literal, this for loop can be avoided or simplified. Maybe just replacing the first occurrence with an if and then replacing all other occurrences with a single call to Replace.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Totally right. Nice! I think this refactoring addresses your other issues/questions with this function as well.

@pdrum
Copy link
Collaborator

pdrum commented Aug 27, 2018

@justnoise Thank you so much for the changes. It looks great.

I will merge this along with #51 on Thursday or Friday to address issues tagged with this milestone. Before that I will add some tests in another PR and perform some manual checks to make sure everything works and all those issues are resolved.

I opened #51 a while ago but it's not reviewed yet. Would you consider reviewing it if you felt like it maybe?

Also I was wondering if you could take the time to squash the two last commits, so that the last one pertinent to renaming of imports won't appear in git history.

@justnoise
Copy link
Contributor Author

Good call on squashing the last commit. Thanks for the good review and pushing all this through. Due to the lack of activity in this repo, I didn't expect to see these changes merged (I made the change so I could use genny in one of my projects...) so I'm really happy with how this turned out.

@pdrum pdrum changed the base branch from master to release-1.0.0 August 30, 2018 08:15
@pdrum pdrum merged commit 758fd2f into cheekybits:release-1.0.0 Aug 30, 2018
@pdrum pdrum mentioned this pull request Aug 30, 2018
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.

None yet

3 participants