aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/parser/proto_ast/common.cpp
blob: a9d1b9d268eafa96717b50c97b087288f9bdec25 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include "common.h"

namespace NProtoAST {

IErrorCollector::IErrorCollector(size_t maxErrors)
    : MaxErrors(maxErrors)
    , NumErrors(0)
{
}

IErrorCollector::~IErrorCollector()
{
}

void IErrorCollector::Error(ui32 line, ui32 col, const TString& message) {
    if (NumErrors + 1 == MaxErrors) {
        AddError(0, 0, "Too many errors");
        ++NumErrors;
    }

    if (NumErrors >= MaxErrors) {
        ythrow TTooManyErrors() << "Too many errors";
    }

    AddError(line, col, message);
    ++NumErrors;
}

TErrorOutput::TErrorOutput(IOutputStream& err, const TString& name, size_t maxErrors)
    : IErrorCollector(maxErrors)
    , Err(err)
    , Name(name)
{
}

TErrorOutput::~TErrorOutput()
{
}

void TErrorOutput::AddError(ui32 line, ui32 col, const TString& message) {
    if (!Name.empty()) {
        Err << "Query " << Name << ": ";
    }
    Err << "Line " << line << " column " << col << " error: " << message;
}

}