Bug 1399059 - Part 1 - Yield Whitespace from FluentParser. r?Pike
MozReview-Commit-ID: 7ob1sBVwO37
--- a/compare_locales/parser.py
+++ b/compare_locales/parser.py
@@ -691,27 +691,40 @@ class FluentParser(Parser):
super(FluentParser, self).__init__()
self.ftl_parser = FTLParser()
def walk(self, onlyEntities=False):
if not self.ctx:
# loading file failed, or we just didn't load anything
return
resource = self.ftl_parser.parse(self.ctx.contents)
+ last_span_end = 0
for entry in resource.body:
+ if not onlyEntities:
+ if entry.span.start > last_span_end:
+ yield Whitespace(
+ self.ctx, (last_span_end, entry.span.start))
+
if isinstance(entry, ftl.Message):
yield FluentEntity(self.ctx, entry)
elif isinstance(entry, ftl.Junk):
start = entry.span.start
end = entry.span.end
# strip leading whitespace
start += re.match('\s*', entry.content).end()
# strip trailing whitespace
ws, we = re.search('\s*$', entry.content).span()
end -= we - ws
yield Junk(self.ctx, (start, end))
+ last_span_end = entry.span.end
+
+ if not onlyEntities:
+ eof_offset = len(self.ctx.contents)
+ if eof_offset > last_span_end:
+ yield Whitespace(self.ctx, (last_span_end, eof_offset))
+
__constructors = [('\\.dtd$', DTDParser()),
('\\.properties$', PropertiesParser()),
('\\.ini$', IniParser()),
('\\.inc$', DefinesParser()),
('\\.ftl$', FluentParser())]