|
22 | 22 | #include "absl/strings/str_cat.h" |
23 | 23 | #include "absl/strings/str_format.h" |
24 | 24 | #include "absl/strings/string_view.h" |
| 25 | +#include "common/operators.h" |
25 | 26 | #include "common/source.h" |
26 | 27 | #include "parser/internal/lexer.h" |
27 | 28 | #include "parser/options.h" |
28 | 29 | #include "parser/parser_interface.h" |
29 | 30 |
|
30 | 31 | namespace cel::parser_internal { |
| 32 | +namespace { |
| 33 | + |
| 34 | +using CelOperator = ::google::api::expr::common::CelOperator; |
| 35 | + |
| 36 | +const BinaryOpInfo kLogicalOr = {1, CelOperator::LOGICAL_OR, true, |
| 37 | + TokenType::kLogicalOr}; |
| 38 | +const BinaryOpInfo kLogicalAnd = {2, CelOperator::LOGICAL_AND, true, |
| 39 | + TokenType::kLogicalAnd}; |
| 40 | +const BinaryOpInfo kLess = {3, CelOperator::LESS, false, TokenType::kLess}; |
| 41 | +const BinaryOpInfo kLessEqual = {3, CelOperator::LESS_EQUALS, false, |
| 42 | + TokenType::kLessEqual}; |
| 43 | +const BinaryOpInfo kGreater = {3, CelOperator::GREATER, false, |
| 44 | + TokenType::kGreater}; |
| 45 | +const BinaryOpInfo kGreaterEqual = {3, CelOperator::GREATER_EQUALS, false, |
| 46 | + TokenType::kGreaterEqual}; |
| 47 | +const BinaryOpInfo kEqualEqual = {3, CelOperator::EQUALS, false, |
| 48 | + TokenType::kEqualEqual}; |
| 49 | +const BinaryOpInfo kExclamationEqual = {3, CelOperator::NOT_EQUALS, false, |
| 50 | + TokenType::kExclamationEqual}; |
| 51 | +const BinaryOpInfo kIn = {3, CelOperator::IN, false, TokenType::kIn}; |
| 52 | +const BinaryOpInfo kPlus = {4, CelOperator::ADD, false, TokenType::kPlus}; |
| 53 | +const BinaryOpInfo kMinus = {4, CelOperator::SUBTRACT, false, |
| 54 | + TokenType::kMinus}; |
| 55 | +const BinaryOpInfo kAsterisk = {5, CelOperator::MULTIPLY, false, |
| 56 | + TokenType::kAsterisk}; |
| 57 | +const BinaryOpInfo kSlash = {5, CelOperator::DIVIDE, false, TokenType::kSlash}; |
| 58 | +const BinaryOpInfo kPercent = {5, CelOperator::MODULO, false, |
| 59 | + TokenType::kPercent}; |
| 60 | +const BinaryOpInfo kDefaultOpInfo = {0, "", false, TokenType::kError}; |
| 61 | + |
| 62 | +} // namespace |
| 63 | + |
| 64 | +const BinaryOpInfo& GetBinaryOpInfo(TokenType type) { |
| 65 | + switch (type) { |
| 66 | + case TokenType::kLogicalOr: |
| 67 | + return kLogicalOr; |
| 68 | + case TokenType::kLogicalAnd: |
| 69 | + return kLogicalAnd; |
| 70 | + case TokenType::kLess: |
| 71 | + return kLess; |
| 72 | + case TokenType::kLessEqual: |
| 73 | + return kLessEqual; |
| 74 | + case TokenType::kGreater: |
| 75 | + return kGreater; |
| 76 | + case TokenType::kGreaterEqual: |
| 77 | + return kGreaterEqual; |
| 78 | + case TokenType::kEqualEqual: |
| 79 | + return kEqualEqual; |
| 80 | + case TokenType::kExclamationEqual: |
| 81 | + return kExclamationEqual; |
| 82 | + case TokenType::kIn: |
| 83 | + return kIn; |
| 84 | + case TokenType::kPlus: |
| 85 | + return kPlus; |
| 86 | + case TokenType::kMinus: |
| 87 | + return kMinus; |
| 88 | + case TokenType::kAsterisk: |
| 89 | + return kAsterisk; |
| 90 | + case TokenType::kSlash: |
| 91 | + return kSlash; |
| 92 | + case TokenType::kPercent: |
| 93 | + return kPercent; |
| 94 | + default: |
| 95 | + return kDefaultOpInfo; |
| 96 | + } |
| 97 | +} |
31 | 98 |
|
32 | 99 | ParserWorker::ParserWorker( |
33 | 100 | const cel::Source& source, const cel::ParserOptions& options, |
|
0 commit comments