#include "llvm/Support/Allocator.h"
#include "llvm/Support/SMLoc.h"
#include <map>
+#include <system_error>
#include <utility>
namespace llvm {
class Stream {
public:
/// \brief This keeps a reference to the string referenced by \p Input.
- Stream(StringRef Input, SourceMgr &, bool ShowColors = true);
+ Stream(StringRef Input, SourceMgr &, bool ShowColors = true,
+ std::error_code *EC = nullptr);
- Stream(MemoryBufferRef InputBuffer, SourceMgr &, bool ShowColors = true);
+ Stream(MemoryBufferRef InputBuffer, SourceMgr &, bool ShowColors = true,
+ std::error_code *EC = nullptr);
~Stream();
document_iterator begin();
/// @brief Scans YAML tokens from a MemoryBuffer.
class Scanner {
public:
- Scanner(StringRef Input, SourceMgr &SM, bool ShowColors = true);
- Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors = true);
+ Scanner(StringRef Input, SourceMgr &SM, bool ShowColors = true,
+ std::error_code *EC = nullptr);
+ Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors = true,
+ std::error_code *EC = nullptr);
/// @brief Parse the next token and return it without popping it.
Token &peekNext();
if (Current >= End)
Current = End - 1;
+ // propagate the error if possible
+ if (EC)
+ *EC = make_error_code(std::errc::invalid_argument);
+
// Don't print out more errors after the first one we encounter. The rest
// are just the result of the first, and have no meaning.
if (!Failed)
/// @brief Potential simple keys.
SmallVector<SimpleKey, 4> SimpleKeys;
+
+ std::error_code *EC;
};
} // end namespace yaml
return EscapedInput;
}
-Scanner::Scanner(StringRef Input, SourceMgr &sm, bool ShowColors)
- : SM(sm), ShowColors(ShowColors) {
+Scanner::Scanner(StringRef Input, SourceMgr &sm, bool ShowColors,
+ std::error_code *EC)
+ : SM(sm), ShowColors(ShowColors), EC(EC) {
init(MemoryBufferRef(Input, "YAML"));
}
-Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors)
- : SM(SM_), ShowColors(ShowColors) {
+Scanner::Scanner(MemoryBufferRef Buffer, SourceMgr &SM_, bool ShowColors,
+ std::error_code *EC)
+ : SM(SM_), ShowColors(ShowColors), EC(EC) {
init(Buffer);
}
return false;
}
-Stream::Stream(StringRef Input, SourceMgr &SM, bool ShowColors)
- : scanner(new Scanner(Input, SM, ShowColors)), CurrentDoc() {}
+Stream::Stream(StringRef Input, SourceMgr &SM, bool ShowColors,
+ std::error_code *EC)
+ : scanner(new Scanner(Input, SM, ShowColors, EC)), CurrentDoc() {}
-Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors)
- : scanner(new Scanner(InputBuffer, SM, ShowColors)), CurrentDoc() {}
+Stream::Stream(MemoryBufferRef InputBuffer, SourceMgr &SM, bool ShowColors,
+ std::error_code *EC)
+ : scanner(new Scanner(InputBuffer, SM, ShowColors, EC)), CurrentDoc() {}
Stream::~Stream() {}
// Input
//===----------------------------------------------------------------------===//
-Input::Input(StringRef InputContent,
- void *Ctxt,
- SourceMgr::DiagHandlerTy DiagHandler,
- void *DiagHandlerCtxt)
- : IO(Ctxt),
- Strm(new Stream(InputContent, SrcMgr)),
- CurrentNode(nullptr) {
+Input::Input(StringRef InputContent, void *Ctxt,
+ SourceMgr::DiagHandlerTy DiagHandler, void *DiagHandlerCtxt)
+ : IO(Ctxt), Strm(new Stream(InputContent, SrcMgr, false, &EC)),
+ CurrentNode(nullptr) {
if (DiagHandler)
SrcMgr.setDiagHandler(DiagHandler, DiagHandlerCtxt);
DocIterator = Strm->begin();