aboutsummaryrefslogtreecommitdiffstats
path: root/ydb/library/yql/parser/proto_ast/proto_ast.cpp
blob: 1a0a3f0bbd4c01c8021e0bfd4b372761ac0ae2ba (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
#include "proto_ast.h"

using 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;
}