When parsing .x/.L filename() //comment

* empty argument is not an error.
* pass comment to interpreter whether .x was successful or not; it might be an expected-diagnostic
Thus implement comment lexer.


git-svn-id: http://root.cern.ch/svn/root/trunk@47473 27541ba8-7e3a-0410-8455-c3a389f83636
This commit is contained in:
Axel Naumann 2012-11-20 13:15:25 +00:00
parent 83f7b6c23d
commit 546c2b1e61

View File

@ -178,6 +178,19 @@ namespace cling {
return Result.kind != tok::unknown;
}
bool LexComment(Token& Result) {
// only handles "//" for now.
Result.startToken();
LexBlankSpace();
Result.bufStart = curPos;
if (*curPos == '/' && curPos[1] == '/') {
Result.bufEnd = strchr(curPos + 2, '\n');
if (!Result.bufEnd) Result.bufEnd = bufferEnd;
return true;
}
return false;
}
};
MetaProcessor::MetaProcessor(Interpreter& interp) : m_Interp(interp) {
@ -282,11 +295,16 @@ namespace cling {
return false;
}
//TODO: Check if the file exists and is readable.
if (Interpreter::kSuccess
!= m_Interp.loadFile(llvm::StringRef(Tok.getBufStart(), Tok.getLength()))) {
if (Interpreter::kSuccess !=
m_Interp.loadFile(llvm::StringRef(Tok.getBufStart(),
Tok.getLength()))) {
llvm::errs() << "Error in cling::MetaProcessor: load file failed.\n";
if (compRes) *compRes = Interpreter::kFailure;
}
if (CmdLexer.LexComment(Tok)) {
// Forward comments to the interpreter; they might be expected-diags.
m_Interp.declare(llvm::StringRef(Tok.getBufStart(), Tok.getLength()).str());
}
return true;
}
@ -306,18 +324,19 @@ namespace cling {
CmdLexer.LexSpecialSymbol(Tok);
if (Tok.getKind() == tok::l_paren) {
// Good enough for now.
if (!CmdLexer.LexAnyString(Tok)) {
llvm::errs() << "cling::MetaProcessor: Argument list expected.\n";
if (compRes) *compRes = Interpreter::kFailure;
return false;
if (CmdLexer.LexAnyString(Tok)) {
args = llvm::StringRef(Tok.getBufStart(), Tok.getLength());
}
args = llvm::StringRef(Tok.getBufStart(), Tok.getLength());
if (!CmdLexer.LexSpecialSymbol(Tok) && Tok.getKind() == tok::r_paren) {
llvm::errs() << "Error in cling::MetaProcessor: closing parenthesis expected.\n";
if (compRes) *compRes = Interpreter::kFailure;
return false;
}
}
if (CmdLexer.LexComment(Tok)) {
// forward comments to the interpreter; they might be expected-diags.
m_Interp.declare(llvm::StringRef(Tok.getBufStart(), Tok.getLength()).str());
}
if (!executeFile(file.str(), args, result, compRes))
llvm::errs() << "Error in cling::MetaProcessor: execute file failed.\n";
return true;