Skip to content

Commit 1835f1a

Browse files
committed
Update filter and handle nested quotes
1 parent 3123cc6 commit 1835f1a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

py/makeqstrdefs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def qstr_unescape(qstr):
7575
def process_file(f):
7676
re_line = re.compile(r"#[line]*\s(\d+)\s\"([^\"]+)\"")
7777
re_qstr = re.compile(r'MP_QSTR_[_a-zA-Z0-9]+')
78+
re_translate = re.compile(r'translate\(\"((?:(?=(\\?))\2.)*?)\"\)')
7879
output = []
7980
last_fname = None
8081
lineno = 0
@@ -99,8 +100,8 @@ def process_file(f):
99100
name = match.replace('MP_QSTR_', '')
100101
if name not in QSTRING_BLACK_LIST:
101102
output.append('Q(' + qstr_unescape(name) + ')')
102-
for match in re.findall(r'translate\(\"([^\"]+)\"\)', line):
103-
output.append('TRANSLATE("' + match + '")')
103+
for match in re_translate.findall(line):
104+
output.append('TRANSLATE("' + match[0] + '")')
104105
lineno += 1
105106

106107
write_out(last_fname, output)

py/mkrules.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ $(OBJ): | $(HEADER_BUILD)/qstrdefs.enum.h $(HEADER_BUILD)/mpversion.h
7979
# - else, process all source files ($^) [this covers "make -B" which can set $? to empty]
8080
$(HEADER_BUILD)/qstr.i.last: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h
8181
$(STEPECHO) "GEN $@"
82-
$(Q)grep -lE "(MP_QSTR|i18n)" $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) | xargs $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(SRC_QSTR_PREPROCESSOR) >$(HEADER_BUILD)/qstr.i.last;
82+
$(Q)grep -lE "(MP_QSTR|translate)" $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) | xargs $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(SRC_QSTR_PREPROCESSOR) >$(HEADER_BUILD)/qstr.i.last;
8383

8484
$(HEADER_BUILD)/qstr.split: $(HEADER_BUILD)/qstr.i.last $(PY_SRC)/makeqstrdefs.py
8585
$(STEPECHO) "GEN $@"

0 commit comments

Comments
 (0)