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

Add location pointing to the end of a source #30

Merged
merged 1 commit into from
Aug 28, 2023
Merged

Add location pointing to the end of a source #30

merged 1 commit into from
Aug 28, 2023

Conversation

markusrosskopf
Copy link
Contributor

No description provided.

trlc/errors.py Outdated Show resolved Hide resolved
trlc/lexer.py Outdated Show resolved Hide resolved
@markusrosskopf markusrosskopf changed the title Add end location to class Source_Reference Add location pointing to the end of a source Aug 23, 2023
trlc/lexer.py Outdated
def get_end_location(self):
"""Get location pointing to the end of a source."""

lines_in_between = self.lexer.content[self.start_pos : self.end_pos + 1].count("\n")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is too long, the pylint check is failing. You can run this locally with

make lint

trlc/lexer.py Outdated
lines_in_between = self.lexer.content[self.start_pos : self.end_pos + 1].count("\n")
end_line = self.line_no + lines_in_between
n = self.end_pos
while n > self.start_pos:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this logic fully works. For this input file:

'''foo
bar'''

We would get an end location of line 2, column 7, but column should be 6.

trlc/lexer.py Outdated
@@ -108,6 +108,20 @@ def context_lines(self):
return [stripped_line,
" " * stripped_offset + "^" * min(tlen, maxtrail)]

def get_end_location(self):
"""Get location pointing to the end of a source."""
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This docstring should go into the initial declaration of the function, in Location

trlc/lexer.py Outdated
end_line = self.line_no + lines_in_between

end_col = self.end_pos + 1
for n in range(self.end_pos, 0, -1):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That range is too big, you should stop where the token begins, not at 0.

@florianschanda florianschanda merged commit 4d65cf1 into bmw-software-engineering:main Aug 28, 2023
2 checks passed
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