Index: ironruby/Compiler/Parser/Parser.cs
===================================================================
--- ironruby/Compiler/Parser/Parser.cs	(revision 76)
+++ ironruby/Compiler/Parser/Parser.cs	(working copy)
@@ -206,12 +206,14 @@
                 return start;
             }
 
-            SourceSpan merged = new SourceSpan(
-                new SourceLocation(start.Start.Index, start.Start.Line, start.Start.Column),
-                new SourceLocation(end.End.Index, end.End.Line, end.End.Column)
-            );
-
-            return merged;
+            if (start.Start > end.End)
+                return new SourceSpan(
+                    new SourceLocation(start.Start.Index, start.Start.Line, start.Start.Column),
+                    new SourceLocation(start.Start.Index, start.Start.Line, start.Start.Column));
+            else
+                return new SourceSpan(
+                    new SourceLocation(start.Start.Index, start.Start.Line, start.Start.Column),
+                    new SourceLocation(end.End.Index, end.End.Line, end.End.Column));
         }
 
         private LexicalScope/*!*/ EnterScope(LexicalScope/*!*/ scope) {
Index: ironruby/Compiler/Parser/Terminators.cs
===================================================================
--- ironruby/Compiler/Parser/Terminators.cs	(revision 76)
+++ ironruby/Compiler/Parser/Terminators.cs	(working copy)
@@ -70,13 +70,15 @@
         public readonly int _resumePosition;
         public readonly string _resumeLine;
         public readonly int _firstLine;
+        public readonly int _firstLineIndex;
 
-        public HEREDOC(StringType func, string label, int resume_position, String resume_line, int firstLine) {
+        public HEREDOC(StringType func, string label, int resume_position, String resume_line, int firstLine, int firstLineIndex) {
             _func = func;
             _label = label;
             _resumePosition = resume_position;
             _resumeLine = resume_line;
             _firstLine = firstLine;
+            _firstLineIndex = firstLineIndex;
         }
 
         public override string ToString() {
Index: ironruby/Compiler/Parser/Tokenizer.cs
===================================================================
--- ironruby/Compiler/Parser/Tokenizer.cs	(revision 76)
+++ ironruby/Compiler/Parser/Tokenizer.cs	(working copy)
@@ -2716,7 +2716,7 @@
             // skip the rest of the line (the content is stored in heredoc string terminal and tokenized upon restore)
             int resume = _bufferPos;
             _bufferPos = _lineBuffer.Length;
-            _currentString = new HEREDOC(func, tok(), resume, _lineBuffer, _currentLine);
+            _currentString = new HEREDOC(func, tok(), resume, _lineBuffer, _currentLine, _currentLineIndex);
             _tokenValue.SetStringTerminator(_currentString);
 
             // note that if we allow \n in the label we must change this to multi-line token!
@@ -2730,6 +2730,7 @@
             _bufferPos = here._resumePosition;
             _heredocEndLine = _currentLine;
             _currentLine = here._firstLine;
+            _currentLineIndex = here._firstLineIndex;
         }
 
         private Tokens TokenizeHeredoc(HEREDOC/*!*/ heredoc) {
