Closed Bug 1399059 Opened 8 years ago Closed 7 years ago

[compare-locales] Optionally yield Whitespace between Entities in Parser.walk()

Categories

(Localization Infrastructure and Tools :: compare-locales, enhancement)

enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: stas, Assigned: stas)

References

Details

Attachments

(1 file, 7 obsolete files)

We should unify how compare-locales' Parsers handle Whitespace in legacy and Fluent resources. Axel suggested refactoring the whole thing and yielding all inter-Entity whitespace as new Whitespace instances.
Assignee: nobody → stas
Status: NEW → ASSIGNED
Comment on attachment 8910849 [details] Bug 1399059 - Part 1 - Yield Whitespace from FluentParser. https://reviewboard.mozilla.org/r/182322/#review187864 ::: compare_locales/tests/test_dtd.py:131 (Diff revision 1) > escaped value"> > ''') > one, two = list(self.parser) > self.assertEqual(one.position(), (1, 1)) > self.assertEqual(one.value_position(), (1, 16)) > - self.assertEqual(one.position(-1), (2, 1)) > + self.assertEqual(one.position(-1), (1, 23)) That looks like a bug, the `one` entity should start on the 1 row of line 2 ::: compare_locales/tests/test_merge.py:298 (Diff revision 1) > 'details': { > 'l10n.dtd': [ > {'error': u'Unparsed content "<!ENTY bar ' > - u'\'gimmick\'>" ' > + u'\'gimmick\'>\n" ' > u'from line 2 column 1 to ' > - u'line 2 column 22'}, > + u'line 3 column 1'}, Another error position that probably shouldn't change.
Attachment #8910849 - Attachment is obsolete: true
Attachment #8910849 - Flags: review?(l10n)
Attachment #8910850 - Attachment is obsolete: true
Attachment #8910850 - Flags: review?(l10n)
Attachment #8910851 - Attachment is obsolete: true
Attachment #8910851 - Flags: review?(l10n)
Attachment #8910852 - Attachment is obsolete: true
Attachment #8910852 - Flags: review?(l10n)
Attachment #8910854 - Attachment is obsolete: true
Attachment #8910854 - Flags: review?(l10n)
Attachment #8910855 - Attachment is obsolete: true
Attachment #8910855 - Flags: review?(l10n)
Attachment #8910856 - Attachment is obsolete: true
Attachment #8910856 - Flags: review?(l10n)
(In reply to Axel Hecht [:Pike] from comment #9) > That looks like a bug, the `one` entity should start on the 1 row of line 2 > Another error position that probably shouldn't change. Both of these changes are related to the fact that Entities don't include the trailing newline anymore and Junk does include all the trailing whitespace. Also, `position(-1)` returns the end position of the entity.
Comment on attachment 8910853 [details] Bug 1399059 - Yield Whitespace between Entities in Parser.walk(only_localizable=False). https://reviewboard.mozilla.org/r/182332/#review188144 ::: compare_locales/tests/test_ftl.py:155 (Diff revision 3) > +baz = Baz > +''') > + entities = list(self.parser.walk()) > + > + self.assertTrue(isinstance(entities[0], parser.Whitespace)) > + self.assertEqual(entities[0].all, '\n') python-fluent parses comments without the trailing newline but the corresponding span is one char too long. That's why there's only one \n here. I filed bug 1402600.
Comment on attachment 8910853 [details] Bug 1399059 - Yield Whitespace between Entities in Parser.walk(only_localizable=False). https://reviewboard.mozilla.org/r/182332/#review187904 Sweet, thanks. Only one nit about removing that left-over comment for DTDEntity completely, r=me with that. ::: compare_locales/parser.py:307 (Diff revision 2) > -# 6: post comment (and white space) in the same line (dtd only) > -# <--[1] > +# <!-- pre comments --> <--[1] > +# <!ENTITY key "value"> > -# <!-- pre comments --> <--[2] > -# <!ENTITY key "value"> <!-- comment --> > # > -# <-------[3]---------><------[6]------> > +# <-------[2]---------> I've reread this after we talked about this. I think we should just remove this comment alltogether, there's no point in having it here anymore.
Attachment #8910853 - Flags: review?(l10n) → review+
https://hg.mozilla.org/l10n/compare-locales/rev/9d38b940dff1bdca5f08fe2fd053324f6d828346 Bug 1399059 - Yield Whitespace between Entities in Parser.walk(only_localizable=False). r=Pike
It is done.
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
Resolution: --- → FIXED
This patch just made compare-locales unusable. I get over 20 warnings, most of them in en-US, and weirdly enough they seem to happen when the string contains a Z.
Oops. Sorry. The problem is that I used \Z in a character class expression: self._trailingWS = re.compile(r'\s*[\n\Z])', re.M) Which is wrong because it's not a character. The fix is to use a group: self._trailingWS = re.compile(r'\s*(?:\n|\Z)', re.M)
Blocks: 1419782
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: