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

extract comment information #26

Merged
merged 12 commits into from
Sep 12, 2023
Merged

Conversation

affemitkaraffe
Copy link
Collaborator

@affemitkaraffe affemitkaraffe commented Aug 9, 2023

Closes languagetooler-gmbh/languagetool-premium#6216
Closes languagetooler-gmbh/languagetool-premium#6215
Closes languagetooler-gmbh/languagetool-premium#6214

Comment on lines +106 to +120
@property
def author(self):
return re.search(r'<!-- ([A-Z]{2}).*', self.comment.__str__()).group(1)

@property
def date(self):
return re.search(r'<!-- [A-Z]{2}@(\d{4}-\d{2}-\d{2}) - [A-Z]+: [\s\S\n]*?-->', self.comment.__str__()).group(1)

@property
def tag(self):
return re.search(r'<!-- [A-Z]{2}@\d{4}-\d{2}-\d{2} - ([A-Z]+): [\s\S\n]*?-->', self.comment.__str__()).group(1)

@property
def content(self):
return re.search(r'<!-- [A-Z]{2}@\d{4}-\d{2}-\d{2} - [A-Z]+: ([\s\S\n]*?)-->', self.comment.__str__()).group(1)
Copy link
Collaborator

Choose a reason for hiding this comment

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

While this works fine, maybe for the future it might be worth it to use named groups. From Python re docs:
Screenshot 2023-08-24 at 11 22 04 AM

This would allow you to have a single parse_comment() method without the need to do the same regexp matching multiple times against the same string ;)

@affemitkaraffe affemitkaraffe merged commit 808cd95 into main Sep 12, 2023
16 checks passed
@affemitkaraffe affemitkaraffe deleted the cross-language-applicability branch September 12, 2023 15:17
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