bumped simplecpp

This commit is contained in:
Daniel Marjamäki 2019-03-11 18:18:00 +01:00
parent 1657439b18
commit 03c2c88d1e
1 changed files with 36 additions and 19 deletions

View File

@ -555,32 +555,45 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
// string / char literal // string / char literal
else if (ch == '\"' || ch == '\'') { else if (ch == '\"' || ch == '\'') {
std::string prefix;
if (cback() && cback()->name && !std::isspace(prevChar(istr, bom)) && (isStringLiteralPrefix(cback()->str()))) { if (cback() && cback()->name && !std::isspace(prevChar(istr, bom)) && (isStringLiteralPrefix(cback()->str()))) {
prefix = cback()->str();
}
// C++11 raw string literal
if (ch == '\"' && !prefix.empty() && *cback()->str().rbegin() == 'R') {
std::string delim; std::string delim;
currentToken = ch; currentToken = ch;
bool hasR = *cback()->str().rbegin() == 'R'; prefix.resize(prefix.size() - 1);
std::string prefix = cback()->str(); ch = readChar(istr,bom);
if (hasR) { while (istr.good() && ch != '(' && ch != '\n') {
prefix.resize(prefix.size() - 1); delim += ch;
delim = ")";
ch = readChar(istr,bom); ch = readChar(istr,bom);
while (istr.good() && ch != '(' && ch != '\n') {
delim += ch;
ch = readChar(istr,bom);
}
if (!istr.good() || ch == '\n')
// TODO report
return;
} }
const std::string endOfRawString(delim + currentToken); if (!istr.good() || ch == '\n') {
if (outputList) {
Output err(files);
err.type = Output::SYNTAX_ERROR;
err.location = location;
err.msg = "Invalid newline in raw string delimiter.";
outputList->push_back(err);
}
return;
}
const std::string endOfRawString(')' + delim + currentToken);
while (istr.good() && !(endsWith(currentToken, endOfRawString) && currentToken.size() > 1)) while (istr.good() && !(endsWith(currentToken, endOfRawString) && currentToken.size() > 1))
currentToken += readChar(istr,bom); currentToken += readChar(istr,bom);
if (!endsWith(currentToken, endOfRawString)) if (!endsWith(currentToken, endOfRawString)) {
// TODO report if (outputList) {
Output err(files);
err.type = Output::SYNTAX_ERROR;
err.location = location;
err.msg = "Raw string missing terminating delimiter.";
outputList->push_back(err);
}
return; return;
}
currentToken.erase(currentToken.size() - endOfRawString.size(), endOfRawString.size() - 1U); currentToken.erase(currentToken.size() - endOfRawString.size(), endOfRawString.size() - 1U);
if (hasR) currentToken = escapeString(currentToken);
currentToken = escapeString(currentToken);
currentToken.insert(0, prefix); currentToken.insert(0, prefix);
back()->setstr(currentToken); back()->setstr(currentToken);
location.adjust(currentToken); location.adjust(currentToken);
@ -588,12 +601,13 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
location.col += 2 + 2 * delim.size(); location.col += 2 + 2 * delim.size();
else else
location.col += 1 + delim.size(); location.col += 1 + delim.size();
continue; continue;
} }
currentToken = readUntil(istr,location,ch,ch,outputList,bom); currentToken = readUntil(istr,location,ch,ch,outputList,bom);
if (currentToken.size() < 2U) if (currentToken.size() < 2U)
// TODO report // Error is reported by readUntil()
return; return;
std::string s = currentToken; std::string s = currentToken;
@ -604,7 +618,10 @@ void simplecpp::TokenList::readfile(std::istream &istr, const std::string &filen
newlines++; newlines++;
} }
push_back(new Token(s, location)); // push string without newlines if (prefix.empty())
push_back(new Token(s, location)); // push string without newlines
else
back()->setstr(prefix + s);
if (newlines > 0 && lastLine().compare(0,9,"# define ") == 0) { if (newlines > 0 && lastLine().compare(0,9,"# define ") == 0) {
multiline += newlines; multiline += newlines;