Commit b5d6b400 authored by JINMEI Tatuya's avatar JINMEI Tatuya

[2373] supported escaping separaters

parent 5955402e
......@@ -287,17 +287,21 @@ String::handle(MasterLexer& lexer) const {
MasterLexer::Token& token = getLexerImpl(lexer)->token_;
data.clear();
bool escaped = false;
while (true) {
int c = getLexerImpl(lexer)->source_->getChar(); // TODO comment
c = getLexerImpl(lexer)->skipComment(c);
int c = getLexerImpl(lexer)->source_->getChar();
if (!escaped) {
c = getLexerImpl(lexer)->skipComment(c);
}
if (c == '\r' || c == '\n' || c == EOF ||
/* escape consideration */
c == ' ' || c == '\t' || c == '(' || c == ')') {
(!escaped &&
(c == ' ' || c == '\t' || c == '(' || c == ')'))) {
getLexerImpl(lexer)->source_->ungetChar();
token = MasterLexer::Token(&data.at(0), data.size());
return (NULL);
}
escaped = (!escaped && (c == '\\'));
data.push_back(c);
}
}
......
......@@ -314,4 +314,40 @@ TEST_F(MasterLexerStateTest, string) {
stringTokenCheck("followed-by-EOF", s_string.getToken(lexer));
}
TEST_F(MasterLexerStateTest, stringEscape) {
// some of the separate characters should be considered part of the
// string if escaped.
ss << "escaped\\ space ";
ss << "escaped\\\ttab ";
ss << "escaped\\(paren ";
ss << "escaped\\)close ";
ss << "escaped\\;comment ";
ss << "escaped\\\\ backslash "; // second '\' shouldn't escape ' '
lexer.pushSource(ss);
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' at end
stringTokenCheck("escaped\\ space", s_string.getToken(lexer));
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' at end
stringTokenCheck("escaped\\\ttab", s_string.getToken(lexer));
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' at end
stringTokenCheck("escaped\\(paren", s_string.getToken(lexer));
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' at end
stringTokenCheck("escaped\\)close", s_string.getToken(lexer));
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' at end
stringTokenCheck("escaped\\;comment", s_string.getToken(lexer));
EXPECT_EQ(&s_string, State::start(lexer, common_options));
EXPECT_EQ(s_null, s_string.handle(lexer)); // recognize str, see ' ' in mid
stringTokenCheck("escaped\\\\", s_string.getToken(lexer));
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment