aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/core/yson/parser.h
blob: b370811e84cd6da2820b60acdd70621090b98d0a (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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once

#include "public.h"
#include "detail.h"

#include <library/cpp/yt/memory/ref.h>

namespace NYT::NYson {

////////////////////////////////////////////////////////////////////////////////

//! @brief Configuration of yson parser.
struct TYsonParserConfig
{
    //! @brief Enable info about line in error messages
    //!
    //! Makes error messages friendlier but slows down parsing.
    bool EnableLinePositionInfo = false;

    i64 MemoryLimit = std::numeric_limits<i64>::max();

    //! @brief Enable context dumping in error messages
    //!
    //! Makes error messages friendlier but slightly slows down parsing.
    bool EnableContext = true;

    //! @brief Maximum level of nesting of lists and maps.
    int NestingLevelLimit = DefaultYsonParserNestingLevelLimit;
};

class TYsonParser
{
public:
    TYsonParser(IYsonConsumer* consumer, EYsonType type = EYsonType::Node, TYsonParserConfig config = {});
    ~TYsonParser();

    void Read(const char* begin, const char* end, bool finish = false);
    void Read(TStringBuf data);
    void Finish();

    const char* GetCurrentPositionInBlock();

private:
    class TImpl;
    const std::unique_ptr<TImpl> Impl;
};

////////////////////////////////////////////////////////////////////////////////

class TStatelessYsonParser
{
public:
    TStatelessYsonParser(IYsonConsumer* consumer, TYsonParserConfig config = {});
    ~TStatelessYsonParser();

    void Parse(TStringBuf data, EYsonType type = EYsonType::Node);
    void Stop();

private:
    class TImpl;
    const std::unique_ptr<TImpl> Impl;
};

////////////////////////////////////////////////////////////////////////////////

void ParseYsonStringBuffer(TStringBuf buffer, EYsonType type, IYsonConsumer* consumer, TYsonParserConfig config = {});

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NYson