Skip to content

Commit

Permalink
[osh2oil] Fix crash when translating empty here doc.
Browse files Browse the repository at this point in the history
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 committed Sep 9, 2018
1 parent 4f9e4ab commit cba45bb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions core/lexer.py
Expand Up @@ -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
Expand Down
16 changes: 7 additions & 9 deletions tools/osh2oil.py
Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit cba45bb

Please sign in to comment.