Skip to content

Refactor and add wildcard support #9

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

aeijdenberg
Copy link

This PR is in two parts. The first part (first commit) refactors the {find,replace,remove}_op.go code so that the logic that descends lives with the individual token types which are split into separate files.

The second part (second commit) adds the ability to match all elements in an array, and thus be able to add / replace many objects with a single replace op.

Appreciate your consideration - this is a first cut - happy to massage it as needed if the community thinks this would be useful.

Fixes #8.

@aeijdenberg
Copy link
Author

It occurred to me it would be pretty easy to add prepend support at the same time, so I added a commit and test for that, which I think fixes #6.

@cppforlife
Copy link
Owner

@aeijdenberg the reason behind how it's currently structured is that i wanted to keep each operation self contained ie i should be able to add an operation without having to change anything about pointers. conceptually pointer could be pulled out as a separate library and should not know anything about processing operations. additionally im not sure it's actually easier to understand what operation does by looking across different tokens instead of in a single loop. i could see some kind of code sharing between them outside of tokens themselves but i think there needs to be a clear boundary around tokens and processing logic.

@aeijdenberg
Copy link
Author

@cppforlife I'd be willing to try again with the existing structure. I needed to make a degree of structural change as iterating down the list of tokens wouldn't adapt easily to matching more than one element.

There's probably an easy enough way to do it with a stack instead of recursive descent - I'll have a look - it might make the patch easier to review.

I guess it's a trade-off between keeping operations self-contained, vs keeping token logic self-contained. e.g. after the initial refactor, adding token_wildcard.go and token_prepend.go was trivial.

Let me know your thoughts.

@aeijdenberg
Copy link
Author

Added alternate implementation here.

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