Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion parser/internal/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ cc_library(
"//parser:options",
"//parser:parser_interface",
"@com_google_absl//absl/base:nullability",
"@com_google_absl//absl/cleanup",
"@com_google_absl//absl/container:flat_hash_map",
"@com_google_absl//absl/status:statusor",
"@com_google_absl//absl/strings",
Expand Down
6 changes: 6 additions & 0 deletions parser/internal/pratt_parser_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ std::vector<TestCase> GetParserTestCases() {
-123^#1:int64#
)",
},
TestCase{
.source = "9223372036854775807",
.expected_ast = R"(
9223372036854775807^#1:int64#
)",
},
TestCase{
.source = "-9223372036854775808",
.expected_ast = R"(
Expand Down
67 changes: 67 additions & 0 deletions parser/internal/pratt_parser_worker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,79 @@
#include "absl/strings/str_cat.h"
#include "absl/strings/str_format.h"
#include "absl/strings/string_view.h"
#include "common/operators.h"
#include "common/source.h"
#include "parser/internal/lexer.h"
#include "parser/options.h"
#include "parser/parser_interface.h"

namespace cel::parser_internal {
namespace {

using CelOperator = ::google::api::expr::common::CelOperator;

const BinaryOpInfo kLogicalOr = {1, CelOperator::LOGICAL_OR, true,
TokenType::kLogicalOr};
const BinaryOpInfo kLogicalAnd = {2, CelOperator::LOGICAL_AND, true,
TokenType::kLogicalAnd};
const BinaryOpInfo kLess = {3, CelOperator::LESS, false, TokenType::kLess};
const BinaryOpInfo kLessEqual = {3, CelOperator::LESS_EQUALS, false,
TokenType::kLessEqual};
const BinaryOpInfo kGreater = {3, CelOperator::GREATER, false,
TokenType::kGreater};
const BinaryOpInfo kGreaterEqual = {3, CelOperator::GREATER_EQUALS, false,
TokenType::kGreaterEqual};
const BinaryOpInfo kEqualEqual = {3, CelOperator::EQUALS, false,
TokenType::kEqualEqual};
const BinaryOpInfo kExclamationEqual = {3, CelOperator::NOT_EQUALS, false,
TokenType::kExclamationEqual};
const BinaryOpInfo kIn = {3, CelOperator::IN, false, TokenType::kIn};
const BinaryOpInfo kPlus = {4, CelOperator::ADD, false, TokenType::kPlus};
const BinaryOpInfo kMinus = {4, CelOperator::SUBTRACT, false,
TokenType::kMinus};
const BinaryOpInfo kAsterisk = {5, CelOperator::MULTIPLY, false,
TokenType::kAsterisk};
const BinaryOpInfo kSlash = {5, CelOperator::DIVIDE, false, TokenType::kSlash};
const BinaryOpInfo kPercent = {5, CelOperator::MODULO, false,
TokenType::kPercent};
const BinaryOpInfo kDefaultOpInfo = {0, "", false, TokenType::kError};

} // namespace

const BinaryOpInfo& GetBinaryOpInfo(TokenType type) {
switch (type) {
case TokenType::kLogicalOr:
return kLogicalOr;
case TokenType::kLogicalAnd:
return kLogicalAnd;
case TokenType::kLess:
return kLess;
case TokenType::kLessEqual:
return kLessEqual;
case TokenType::kGreater:
return kGreater;
case TokenType::kGreaterEqual:
return kGreaterEqual;
case TokenType::kEqualEqual:
return kEqualEqual;
case TokenType::kExclamationEqual:
return kExclamationEqual;
case TokenType::kIn:
return kIn;
case TokenType::kPlus:
return kPlus;
case TokenType::kMinus:
return kMinus;
case TokenType::kAsterisk:
return kAsterisk;
case TokenType::kSlash:
return kSlash;
case TokenType::kPercent:
return kPercent;
default:
return kDefaultOpInfo;
}
}

ParserWorker::ParserWorker(
const cel::Source& source, const cel::ParserOptions& options,
Expand Down
Loading
Loading