-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexpr-parse.h
More file actions
55 lines (39 loc) · 1.31 KB
/
Copy pathexpr-parse.h
File metadata and controls
55 lines (39 loc) · 1.31 KB
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
#ifndef EXPR_PARSE_H_
#define EXPR_PARSE_H_ 1
#include <cstdio>
#include <cstdint>
#include <memory>
#include <string>
#include "expr.h"
#include "expression-parser.hh"
#include "terminal.h"
namespace expression {
class ParseContext {
public:
enum Flag {
// Ignore expressions whose result are exactly equal to their input.
kIgnoreTrivial = 0x0001,
};
// Finds the longest suffix of `input` that is a valid expression, evaluates
// its, and stores the value in `result`. Returns true on success, and false
// on error.
static bool FindAndEval(const std::string& input,
std::string::size_type* offset, std::string* result,
uint16_t flags = 0,
const Terminal::State* state = nullptr);
void SetError(const yy::ExpressionParser::location_type& l,
const std::string& error);
const std::string& Error() const { return error_; }
void* Scanner() { return scanner_; }
Expression* ParseExpression(const std::string& expression);
private:
friend class yy::ExpressionParser;
void* scanner_;
std::string error_;
std::unique_ptr<Expression> expression_;
};
} // namespace expression
#define YY_DECL \
yy::ExpressionParser::symbol_type yylex(expression::ParseContext* ctx)
YY_DECL;
#endif // !EXPR_PARSE_H_