1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 #pragma once 4 #include <boost/fusion/adapted/struct/adapt_struct.hpp> 5 #include <boost/spirit/home/x3/support/ast/variant.hpp> 6 7 #include <cstdint> 8 #include <list> 9 #include <optional> 10 #include <string> 11 12 namespace redfish 13 { 14 namespace filter_ast 15 { 16 17 namespace x3 = boost::spirit::x3; 18 19 // Represents a string literal 20 // (ie 'Enabled') 21 struct QuotedString : std::string 22 {}; 23 24 // Represents a string that matches an identifier 25 // Looks similar to a json pointer 26 struct UnquotedString : std::string 27 {}; 28 29 // Because some program elements can reference BooleanOp recursively, 30 // they need to be forward declared so that x3::forward_ast can be used 31 struct LogicalAnd; 32 struct Comparison; 33 using BooleanOp = 34 x3::variant<x3::forward_ast<Comparison>, x3::forward_ast<LogicalAnd>>; 35 36 enum class ComparisonOpEnum 37 { 38 Invalid, 39 Equals, 40 NotEquals, 41 GreaterThan, 42 GreaterThanOrEqual, 43 LessThan, 44 LessThanOrEqual 45 }; 46 47 // An expression that has been negated with not 48 struct LogicalNot 49 { 50 std::optional<char> isLogicalNot; 51 BooleanOp operand; 52 }; 53 54 using Argument = x3::variant<int64_t, double, UnquotedString, QuotedString>; 55 56 struct Comparison 57 { 58 Argument left; 59 ComparisonOpEnum token = ComparisonOpEnum::Invalid; 60 Argument right; 61 }; 62 63 struct LogicalOr 64 { 65 LogicalNot first; 66 std::list<LogicalNot> rest; 67 }; 68 struct LogicalAnd 69 { 70 LogicalOr first; 71 std::list<LogicalOr> rest; 72 }; 73 } // namespace filter_ast 74 } // namespace redfish 75 76 BOOST_FUSION_ADAPT_STRUCT(redfish::filter_ast::Comparison, left, token, right); 77 BOOST_FUSION_ADAPT_STRUCT(redfish::filter_ast::LogicalNot, isLogicalNot, 78 operand); 79 BOOST_FUSION_ADAPT_STRUCT(redfish::filter_ast::LogicalOr, first, rest); 80 BOOST_FUSION_ADAPT_STRUCT(redfish::filter_ast::LogicalAnd, first, rest); 81