Skip to content

Commit

Permalink
Port the comment and section span handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Zibi Braniecki committed Oct 6, 2017
1 parent 43eb708 commit b11d3a6
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
15 changes: 15 additions & 0 deletions fluent/syntax/ftlstream.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,21 @@ def is_number_start(self):

return (cc >= 48 and cc <= 57) or cc == 45

def is_peek_next_line_comment(self):
if not self.current_peek_is('\n'):
return False

self.peek()

if self.current_peek_is('/'):
self.peek()
if self.current_peek_is('/'):
self.reset_peek()
return True

self.reset_peek()
return False

def is_peek_next_line_variant_start(self):
if not self.current_peek_is('\n'):
return False
Expand Down
15 changes: 8 additions & 7 deletions fluent/syntax/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def parse(self, source):
else:
entries.append(entry)

ps.skip_inline_ws()
ps.skip_blank_lines()

res = ast.Resource(entries, comment)
Expand Down Expand Up @@ -90,6 +91,11 @@ def get_entry(self, ps):
if ps.current_is('/'):
comment = self.get_comment(ps)

# The Comment content doesn't include the trailing newline. Consume
# this newline here to be ready for the next entry. undefined stands
# for EOF.
ps.expect_char('\n' if ps.current() else None)

if ps.current_is('['):
return self.get_section(ps, comment)

Expand Down Expand Up @@ -118,12 +124,11 @@ def until_eol(x):
content += ch
ch = ps.take_char(until_eol)

ps.next()

if ps.current_is('/'):
if ps.is_peek_next_line_comment():
content += '\n'
ps.next()
ps.expect_char('/')
ps.expect_char('/')
ps.take_char_if(' ')
else:
break
Expand All @@ -144,10 +149,6 @@ def get_section(self, ps, comment):
ps.expect_char(']')
ps.expect_char(']')

ps.skip_inline_ws()

ps.expect_char('\n')

return ast.Section(symb, comment)

@with_span
Expand Down

0 comments on commit b11d3a6

Please sign in to comment.