aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/sql/v1/complete/syntax/cursor_token_context.h
blob: 9db544b5234554126966d46cf20dff56403f5f13 (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
#pragma once

#include <yql/essentials/sql/v1/complete/core/input.h>
#include <yql/essentials/sql/v1/complete/text/word.h>

#include <yql/essentials/parser/lexer_common/lexer.h>

#include <util/generic/maybe.h>

namespace NSQLComplete {

    using NSQLTranslation::ILexer;
    using NSQLTranslation::TParsedToken;
    using NSQLTranslation::TParsedTokenList;

    struct TCursor {
        TMaybe<size_t> PrevTokenIndex = Nothing();
        size_t NextTokenIndex = PrevTokenIndex ? *PrevTokenIndex : 0;
        size_t Position = 0;
    };

    struct TRichParsedToken {
        const TParsedToken* Base = nullptr;
        size_t Index = 0;
        size_t Position = 0;

        bool IsLiteral() const;
    };

    struct TCursorTokenContext {
        TParsedTokenList Tokens;
        TVector<size_t> TokenPositions;
        TCursor Cursor;

        TMaybe<TRichParsedToken> Enclosing() const;
        TMaybe<TRichParsedToken> MatchCursorPrefix(const TVector<TStringBuf>& pattern) const;
    };

    bool GetStatement(
        ILexer::TPtr& lexer,
        const TMaterializedInput& input,
        TCompletionInput& output,
        size_t& output_position);

    bool GetCursorTokenContext(
        ILexer::TPtr& lexer,
        TCompletionInput input,
        TCursorTokenContext& context);

} // namespace NSQLComplete