aboutsummaryrefslogtreecommitdiffstats
path: root/document/src/vespa/document/select/simpleparser.h
blob: b1867f921fe26cf3b595168b38d2460f35b2982d (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "node.h"
#include "valuenodes.h"
#include "operator.h"

namespace document::select::simple {

class Parser {
public:
    virtual ~Parser() { }
    virtual bool parse(vespalib::stringref s) = 0;
    vespalib::stringref getRemaining() const { return _remaining; }
protected:
    void setRemaining(vespalib::stringref s) { _remaining = s; }
private:
    vespalib::stringref _remaining;
};

class NodeResult {
public:
    Node::UP getNode() { return std::move(_node); }
protected:
    void setNode(Node::UP node) { _node = std::move(node); }
private:
    Node::UP            _node;
};

class ValueResult {
public:
    ValueNode::UP stealValue() { return std::move(_value); }
    const ValueNode & getValue() const { return *_value; }
protected:
    void setValue(ValueNode::UP node) { _value = std::move(node); }
private:
    ValueNode::UP            _value;
};

class IdSpecParser : public Parser, public ValueResult
{
public:
    IdSpecParser(const BucketIdFactory& bucketIdFactory) :
        _bucketIdFactory(bucketIdFactory)
    {}
    bool parse(vespalib::stringref s) override;
    const IdValueNode & getId() const { return static_cast<const IdValueNode &>(getValue()); }
    bool isUserSpec() const { return getId().getType() == IdValueNode::USER; }
private:
    const BucketIdFactory & _bucketIdFactory;
};

class OperatorParser : public Parser
{
public:
    bool parse(vespalib::stringref s) override;
    const Operator * getOperator() const { return _operator; }
private:
    const Operator *_operator;
};

class StringParser : public Parser, public ValueResult
{
public:
    bool parse(vespalib::stringref s) override;
};

class IntegerParser : public Parser, public ValueResult
{
public:
    bool parse(vespalib::stringref s) override;
};

class SelectionParser : public Parser, public NodeResult
{
public:
    SelectionParser(const BucketIdFactory& bucketIdFactory) :
        _bucketIdFactory(bucketIdFactory)
    {}
    bool parse(vespalib::stringref s) override;
private:
    const BucketIdFactory & _bucketIdFactory;
};

}