Do not skip comments in strings. Fixes ROOT-6692.
This commit is contained in:
parent
052db346d8
commit
7efdd91555
@ -19,7 +19,18 @@ namespace cling {
|
||||
Token Tok;
|
||||
const char* curPos = line.data();
|
||||
do {
|
||||
MetaLexer::LexPunctuatorAndAdvance(curPos, Tok);
|
||||
// If the input is "some//string" or '//some/string' we need to disable
|
||||
// the comment checks.
|
||||
bool hasQuoteOrAnterisk = false;
|
||||
for (unsigned i = 0, e = m_ParenStack.size(); i < e; ++i) {
|
||||
int entry = m_ParenStack[i];
|
||||
if (entry == (int)tok::quote || entry == (int)tok::apostrophe) {
|
||||
hasQuoteOrAnterisk = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
MetaLexer::LexPunctuatorAndAdvance(curPos, Tok,
|
||||
/*skipComments*/hasQuoteOrAnterisk);
|
||||
int kind = (int)Tok.getKind();
|
||||
|
||||
// if (kind == tok::hash) {
|
||||
@ -31,11 +42,11 @@ namespace cling {
|
||||
// if (Tok.getKind() == tok::ident) {
|
||||
// if (Tok.getIdent().startswith("if")) {
|
||||
// Res = kIncomplete;
|
||||
// m_ParenStack.push(kind);
|
||||
// m_ParenStack.push_back(kind);
|
||||
// }
|
||||
// else if (Tok.getIdent().startswith("end")) {
|
||||
// assert(m_ParenStack.top() == kind && "No coresponding # to pop?");
|
||||
// m_ParenStack.pop();
|
||||
// assert(m_ParenStack.back() == kind && "No coresponding # to pop?");
|
||||
// m_ParenStack.pop_back();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@ -45,7 +56,7 @@ namespace cling {
|
||||
// enounter matching " or '
|
||||
if (kind != (int)Tok.getKind()) {
|
||||
Res = kIncomplete;
|
||||
m_ParenStack.push(kind);
|
||||
m_ParenStack.push_back(kind);
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
@ -60,15 +71,15 @@ namespace cling {
|
||||
Res = kMismatch;
|
||||
break;
|
||||
}
|
||||
int prev = m_ParenStack.top();
|
||||
int prev = m_ParenStack.back();
|
||||
if (prev != kind - 1) {
|
||||
Res = kMismatch;
|
||||
break;
|
||||
}
|
||||
m_ParenStack.pop();
|
||||
m_ParenStack.pop_back();
|
||||
}
|
||||
else
|
||||
m_ParenStack.push(kind);
|
||||
m_ParenStack.push_back(kind);
|
||||
}
|
||||
}
|
||||
while (Tok.isNot(tok::eof));
|
||||
@ -77,8 +88,8 @@ namespace cling {
|
||||
Res = kIncomplete;
|
||||
|
||||
if (!m_Input.empty()) {
|
||||
if (!m_ParenStack.empty() && (m_ParenStack.top() == tok::quote
|
||||
|| m_ParenStack.top() == tok::apostrophe))
|
||||
if (!m_ParenStack.empty() && (m_ParenStack.back() == tok::quote
|
||||
|| m_ParenStack.back() == tok::apostrophe))
|
||||
m_Input.append("\\n");
|
||||
else
|
||||
m_Input.append("\n");
|
||||
@ -93,7 +104,6 @@ namespace cling {
|
||||
|
||||
void InputValidator::reset() {
|
||||
m_Input = "";
|
||||
while (!m_ParenStack.empty())
|
||||
m_ParenStack.pop();
|
||||
m_ParenStack.clear();
|
||||
}
|
||||
} // end namespace cling
|
||||
|
@ -27,18 +27,13 @@ namespace cling {
|
||||
///
|
||||
class InputValidator {
|
||||
private:
|
||||
enum {
|
||||
kTick = clang::tok::r_brace + 1,
|
||||
kQuote
|
||||
};
|
||||
|
||||
///\brief The input being collected.
|
||||
///
|
||||
std::string m_Input;
|
||||
|
||||
///\brief Stack used for checking the brace balance.
|
||||
///
|
||||
std::stack<int> m_ParenStack;
|
||||
std::deque<int> m_ParenStack;
|
||||
|
||||
public:
|
||||
InputValidator() {}
|
||||
|
@ -121,11 +121,12 @@ namespace cling {
|
||||
}
|
||||
}
|
||||
|
||||
void MetaLexer::LexPunctuatorAndAdvance(const char*& curPos, Token& Tok) {
|
||||
void MetaLexer::LexPunctuatorAndAdvance(const char*& curPos, Token& Tok,
|
||||
bool skipComments /*false*/) {
|
||||
Tok.startToken(curPos);
|
||||
while (true) {
|
||||
// On comment skip until the eof token.
|
||||
if (curPos[0] == '/' && curPos[1] == '/') {
|
||||
if (!skipComments && curPos[0] == '/' && curPos[1] == '/') {
|
||||
while (*curPos != '\0' && *curPos != '\r' && *curPos != '\n')
|
||||
++curPos;
|
||||
if (*curPos == '\0') {
|
||||
|
@ -89,7 +89,8 @@ namespace cling {
|
||||
|
||||
static void LexPunctuator(char C, Token& Tok);
|
||||
// TODO: Revise. We might not need that.
|
||||
static void LexPunctuatorAndAdvance(const char*& curPos, Token& Tok);
|
||||
static void LexPunctuatorAndAdvance(const char*& curPos, Token& Tok,
|
||||
bool skipComments = false);
|
||||
static void LexQuotedStringAndAdvance(const char*& curPos, Token& Tok);
|
||||
void LexConstant(char C, Token& Tok);
|
||||
void LexIdentifier(char C, Token& Tok);
|
||||
|
Loading…
Reference in New Issue
Block a user