Skip to content

Commit

Permalink
backport fixes for carriage return to stages 0 and 1
Browse files Browse the repository at this point in the history
  • Loading branch information
NotFound committed Jun 9, 2012
1 parent 4cdcb56 commit c76378b
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
13 changes: 10 additions & 3 deletions token.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// token.cpp
// Revision 25-may-2012
// Revision 9-jun-2012

#include "token.h"
#include "errors.h"
Expand Down Expand Up @@ -155,6 +155,7 @@ bool Token::isspace() const
(s.empty() ||
s[0] == ' ' ||
s[0] == '\t' ||
s[0] == '\r' ||
s[0] == '\n'
));
}
Expand Down Expand Up @@ -310,7 +311,10 @@ Token Tokenizer::getheredoc()
std::string mark;
char c;
while ((c = getchar()) != '\n' && c != '\0')
mark += c;
{
if (c != '\r')
mark += c;
}
if (c == 0)
throw SyntaxError ("Unterminated heredoc ",
Token(TokenTQuoted, "<<:", linenum, name));
Expand All @@ -320,7 +324,10 @@ Token Tokenizer::getheredoc()
do {
line = "";
while ((c = getchar()) != '\n' && c != '\0')
line += c;
{
if (c != '\r')
line += c;
}
if (c == 0)
throw SyntaxError ("Unterminated heredoc ",
Token(TokenTQuoted, "<<:", linenum, name));
Expand Down
16 changes: 11 additions & 5 deletions winxedst1.winxed
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

function isspace(string c)
{
return c == " " || c == "\n" || c == "\t";
return c == " " || c == "\n" || c == "\t" || c == "\r";
}

function isdigit(string c)
Expand Down Expand Up @@ -450,14 +450,17 @@ function getheredoc(var tk, string start, int linenum)
switch (c) {
case "":
UnterminatedHeredoc(tk, linenum);
case "\r":
break; // Quick fix for windows line-ending text files
case "\"":
case "\\":
// Encode the mark the same way as the heredoc content
// to simplify its detection
c = "\\" + c;
mark = mark + "\\" + c;
break;
default:
mark = mark + c;
}
mark = mark + c;
}
mark = mark + ":>>";

Expand All @@ -469,12 +472,15 @@ function getheredoc(var tk, string start, int linenum)
switch (c) {
case "":
UnterminatedHeredoc(tk, linenum);
case "\r":
break; // Quick fix for windows line-ending text files
case "\"":
case "\\":
c = "\\" + c;
line = line + "\\" + c;
break;
default:
line = line + c;
}
line = line + c;
}
if (line != mark)
content = content + line + "\\n";
Expand Down

0 comments on commit c76378b

Please sign in to comment.