Open pjljvandelaar opened 2 years ago
The following real world example shows why comment handling is needed.
- return not
- (R1 (1).X > R2 (2).X -- R1 on the right of R2
- or else R2 (1).X > R1 (2).X -- R2 on the right of R1
- or else R1 (1).Y > R2 (2).Y -- R1 below R2
- or else R2 (1).Y > R1 (2).Y); -- R1 above R2
+ return
+ (((R1 (1).X <= R2 (2).X) and then (R2 (1).X <= R1 (2).X))
+ and then (R1 (1).Y <= R2 (2).Y))
+ and then (R2 (1).Y <= R1 (2).Y); -- R1 above R2
Although one might wonder whether the comment is still correct after the transformation.
Comments within place holders are part of that place holder. In find and replace, these comments are thus just copied as part of the place holder. Yet how to handle comments surrounding the place holders? Users typically associate these surrounding comments in a particular way with the place holder, e.g. comments before a function describe that function, comment after a statement describe that statement. We however have observed quite some different heuristics in different code bases.
Example: Suppose, the user wants to swap f and g.
-- C0
f;
-- C1
g;
-- C2
What does he wants as end result?
-- C0
g;
-- C1
f;
-- C2
-- C1
g;
-- C2
-- C0
f;
g;
-- C2
-- C0
f;
-- C1
or even
-- C1
g;
-- C2
-- C0
f;
-- C1
Proposed solution:
Questions:
Does a user want to specify that he only wants the last part
of a comment?
What is a comment?
-- x
-- y
Two comment lines: One or two comments?
-- x
-- y
Two comments lines separated by a white line: One or two comments?
So has
-- $M_X
-- $M_Y
a clear interpretation?
Pattern
-- $S_comment_before
function $S_function
will match instance
-- Describing comment of my_function
function my_function
Pattern
-- $M_comment_before
function $S_function
will match instance
-- Describing multiline
-- comment of my_function
function my_function
The following design is proposed (for now):
In find patterns
Note: using a check function, a comment can still be matched to a particular text.
In replace patterns
We would like to give the user more control over the comments: Currently, before and after trivia are supported but this can lead to duplication of comments. E.g. with find pattern
and replace pattern
with
before
andafter
equal toAll_Trivia
.The find pattern matches the following instance
results in the replacement
However, we also want to enable tools to add marks to the code, such that consequent changes are limited to the marked sections. These comments should NOT be accessible by other
users
.