Skip to content

Commit

Permalink
make comment regex a constant
Browse files Browse the repository at this point in the history
  • Loading branch information
affemitkaraffe committed Sep 21, 2023
1 parent e725ab6 commit 4de0d6a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions scripts/lib/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from os import path
import re

RULES_PATH = path.join('src', 'main', 'resources', 'org', 'languagetool', 'rules')
LOCALES = {'de', 'es', 'en', 'fr', 'nl', 'pt'}
Expand All @@ -12,3 +13,6 @@
"personal": ['clarity', 'general', 'informal', 'positive', 'povadd'],
"expressive": ['clarity', 'general']
}

COMMENT_REGEX = re.compile(r'<!-- (?P<author>\w+)@(?P<date>\d{4}-\d{2}-\d{2}) - (?P<tag>[A-Z]+): '
r'(?P<content>[\s\S\n]*?)')
8 changes: 3 additions & 5 deletions scripts/lib/elements.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import re
from lxml import etree
from typing import List
from constants import *


class ToneTag:
Expand Down Expand Up @@ -62,9 +62,8 @@ def is_goal_specific(self):
@property
def comments(self):
if self.xml_node.tag in ["rule", "rulegroup"]:
regex = re.compile(r'<!-- [A-Z]{2}@\d{4}-\d{2}-\d{2} - [A-Z]+: [\s\S\n]*?-->')
comments = self.xml_node.xpath("./comment()[not(preceding-sibling::pattern)]")
return [Comment(c) for c in comments if re.fullmatch(regex, str(c))]
return [Comment(c) for c in comments if re.fullmatch(COMMENT_REGEX, str(c))]

# This is stupid, but whatever, it works.
@staticmethod
Expand Down Expand Up @@ -110,5 +109,4 @@ def __str__(self):
return self.comment

def parse_comment(self):
return re.search(r'<!-- (?P<author>\w+)@(?P<date>\d{4}-\d{2}-\d{2}) - (?P<tag>[A-Z]+):'
r' (?P<content>[\s\S\n]*?)-->', self.comment.__str__())
return re.search(COMMENT_REGEX, self.comment.__str__())

0 comments on commit 4de0d6a

Please sign in to comment.