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

Concatenate prefixes with bodies #100

Open
jvcoutinho opened this issue Aug 27, 2019 · 4 comments
Open

Concatenate prefixes with bodies #100

jvcoutinho opened this issue Aug 27, 2019 · 4 comments

Comments

@jvcoutinho
Copy link
Collaborator

Currently, prefixes store all of the special tokens (white spaces and comments) that occur prior to a token. On the other hand, the bodies store all of the tokens of a node. This is in some way useful to analyse indentation and spacing, but it has some weird colateral effects:

Suppose base has only one attribute int a. Left pushes a 4 spaces and right pushes a 8 spaces.
If the merge ignores whitespaces, right is chosen as it has more characters in the prefix than left does. Otherwise, a conflict is reported. But it is reported in this way:

<<<<<<< MINE
=======
    
>>>>>>> YOURS
int a;

The conflicting contents are only whitespaces and a lost its indentation. It should be reported like this:

<<<<<<< MINE
    int a;
=======
         int a;
>>>>>>> YOURS

Now, suppose the same scenario but instead of an attribute we have a method

void m() {

}

Left pushes all of m's lines 4 spaces and right pushes them 8 spaces. Considering whitespaces ignored, we have:

        void m() {

}

That means right's prefix was chosen (that's why the first line is indented 8 spaces), but the rest was decided by textual merge (that's why the third line is not indented at all).

So, instead of manipulating prefix and body to solve this specific scenario, I propose concatenating them at instancing level. That means the body will store all of the special tokens that occur prior to the first token + all of the node's content. Textual merge will take care of handling all of the spacing.
This solves these scenarios, makes whitespaces ignoration more responsive and eliminates the necessity of gambiarras. In the future, it can also make the output of a diff tool more intuitive.

@jvcoutinho jvcoutinho changed the title Prefixes separated from bodies leads to weird outputs Concatenate prefixes with bodies Aug 27, 2019
@guilhermejccavalcanti
Copy link
Owner

So, you want to move all the "\t\r\n etc." that appears on FSTTerminal.getPrefix() to (concatenate with) FSTTerminal.getBody() ?

@jvcoutinho
Copy link
Collaborator Author

@guilhermejccavalcanti Exactly.

@pauloborba
Copy link
Collaborator

@jvcoutinho try a few examples with comments. seems to work for whitespace. not so sure about the implications on how comments are handled.

@pauloborba
Copy link
Collaborator

@jvcoutinho what about one developer changes the last line of a comment, and the other changes the first line of a method declaration?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants