-
Notifications
You must be signed in to change notification settings - Fork 1
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
Location doesn't handle multiline nodes #36
Comments
True this is just a missing feature in CompileError. It already has the full location but does not really know how to render them. |
Ok nice! I added some methods to Location and Token, so we can merge via method calls.
|
There are already merge functions in location.swift. I don't quite get the
point of also having methods dangling of the objects.
Either way we sould choose one approach and stick to it. At least there
should only be the merging logic once.
…On Mon, 12 Sep 2022, 11:50 Johannes Zottele, ***@***.***> wrote:
Ok nice!
I added some methods to Location and Token, so we can merge via method
calls.
someTokenOrLocation.mergeLocations(otherTokenOrLocation)
—
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFBZOL6L63PXTGU4Y42JVZDV534GLANCNFSM6AAAAAAQKJGJWM>
.
You are receiving this because you were assigned.Message ID:
***@***.***>
|
The merge logic is bundled in |
This comment was marked as outdated.
This comment was marked as outdated.
I found a mistake in the // Lets assume b is the last one
var endCol = b.endCol
// Now check if we made another mistake
if (a.line > b.line) || (a.line == b.line && a.endLine > b.endLine) {
endCol = a.endCol
} The correct condition would be if (a.endLine > b.endLine) || (a.endLine == b.endLine && a.endCol > b.endCol) { However I would suggest that we take advantage of the swift tuple comparison to implement the logic: // Lets assume a is the first one
var col = a.col
// Now check if we made a mistake and if so lets correct for it
if (b.line, b.col) < (a.line, a.col) {
col = b.col
}
// Lets assume b is the last one
var endCol = b.endCol
// Now check if we made another mistake
if (b.endLine, b.endCol) < (a.endLine, a.endCol) {
endCol = a.endCol
} Is it ok for you if I use the second implementation? I think it is easier to understand |
Sure go ahead, could you also add some unit tests? |
Ok I will work on this now. |
I actually think it might be preferable to have many constructors of location which take tokens and other locations and merge them. Since it is a natural way to create new Locations by merging two existing ones. |
Also I now have implemented multiline error highlighting, however I think that this issue should stay open since we should aim to not highlight the whole class but probably only the class keyword and the name:
This would make the error message much shorter, easier to read without loosing any meaningful information. |
Yes, this is done by the parser by using not the closing bracket as second location mergepoint but the first one. |
Well I thought that in the typechecker we could create another |
This code results in the following error message:
As you can see, the first error, the class definition is completely marked (as it should be) since it is a one-liner, but in the second error message only the first letter is marked.
This problem holds for all multiline expressions.
The text was updated successfully, but these errors were encountered: