Permalink
Browse files

[osh2oil] Fix crash when translating empty here doc.

It seems like has to have another redirect after it.  Example:

git/t/t4015-diff-whitespace.sh

The translation no longer crashes, but it's still wrong.
  • Loading branch information...
Andy Chu
Andy Chu committed Sep 9, 2018
1 parent 4f9e4ab commit cba45bbed7929ca295eb5660f608cc1c2ffc2489
Showing with 10 additions and 9 deletions.
  1. +3 −0 core/lexer.py
  2. +7 −9 tools/osh2oil.py
View
@@ -197,6 +197,9 @@ def _Read(self, lex_mode):
line_id, line, line_pos = self.line_reader.GetLine()
if line is None: # no more lines
# NOTE: Eof_Real has no contents, but it has a span_id because we want
# to retrieve the path and line number in ui.PrettyPrintError().
# The line_id might be -1.
span_id = self.line_lexer.GetSpanIdForEof()
t = ast.token(Id.Eof_Real, '', span_id)
return t
View
@@ -38,20 +38,19 @@ def __init__(self, arena, f):
def PrintUntil(self, until_span_id):
# Sometimes we add +1
assert until_span_id < const.NO_INTEGER, 'Missing span ID, got %d' % until_span_id
#log('PrintUntil %d', until_span_id)
assert until_span_id < const.NO_INTEGER, \
'Missing span ID, got %d' % until_span_id
for span_id in range(self.next_span_id, until_span_id):
#log('Looking up span id %d', span_id)
span = self.arena.GetLineSpan(span_id)
#log('SPAN %s', span)
assert span.line_id != -1, 'Invalid span %d: %s' % (span_id, span)
# A span for Eof may have a line_id of -1 when the file is completely
# empty.
if span.line_id == -1:
continue
line = self.arena.GetLine(span.line_id)
piece = line[span.col : span.col + span.length]
self.f.write(piece)
# Spacing
#self.f.write('%r' % piece)
#self.f.write('__')
self.next_span_id = until_span_id
@@ -1107,7 +1106,6 @@ def DoWordPart(self, node, local_symbols, quoted=False):
span_id = word.LeftMostSpanForPart(node)
if span_id is not None and span_id != const.NO_INTEGER:
span = self.arena.GetLineSpan(span_id)
#print(span)
self.cursor.PrintUntil(span_id)

0 comments on commit cba45bb

Please sign in to comment.