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

refactoring support #8

Open
kevinushey opened this issue Feb 24, 2016 · 0 comments
Open

refactoring support #8

kevinushey opened this issue Feb 24, 2016 · 0 comments

Comments

@kevinushey
Copy link
Owner

Thinking out loud:

  1. Need a function that returns a set of 'actions'; ie, mutations to the document that need to be made. These will effectively be replacements of a certain range, e.g. to rename an identifier, or to move a comment (delete code in one range, add in other range). Should ensure these are non-overlapping, and returned in reverse order so it's easy to apply sequentially.
  2. Use something like a visitor pattern to generate actions.

Pseudo-code that would be nice to write:

// get AST
std::string code("x <- x + 1");
auto AST = parse(code);

// prepare refactor
std::vector<Visitor> visitors;
std::vector<Action> actions;

// add a visitor that renames 'foo' to 'bar'
visitors.push_back([](const Node& node, std::vector<Action>* pActions) {
    if (node.token.contentsEqual("foo")) {
        pActions->push_back(token.range(), "bar");
    }
});

// apply visitors
apply(AST, visitors, &actions);

// do something with resulting actions
return actions;
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

No branches or pull requests

1 participant