8 #ifndef PXR_USD_SDF_PREDICATE_EXPRESSION_PARSER_H
9 #define PXR_USD_SDF_PREDICATE_EXPRESSION_PARSER_H
17 #include "pxr/base/pegtl/pegtl.hpp"
26 size_t trimBothSides,
unsigned int* numLines=NULL);
35 _stacks.back().PushCall(
36 kind, std::move(_funcName), std::move(_funcArgs));
46 _funcArgs.push_back({ std::move(_funcKwArgName), val });
47 _funcKwArgName.clear();
59 _stacks.back().PushExpr(std::move(innerExpr));
76 return (left <
right) || (left ==
right && left != Op::Not);
79 while (!opStack.empty() && higherPrec(opStack.back(),
op)) {
82 opStack.push_back(op);
87 std::vector<SdfPredicateExpression::FnArg> &&
args) {
90 kind, std::move(
name), std::move(
args) }));
94 exprStack.push_back(std::move(expr));
98 while (!opStack.empty()) {
111 exprStack.pop_back();
121 exprStack.pop_back();
124 op, std::move(left), std::move(right))
130 std::vector<SdfPredicateExpression::Op> opStack;
131 std::vector<SdfPredicateExpression> exprStack;
134 std::vector<_Stack> _stacks;
136 std::string _funcName;
137 std::string _funcKwArgName;
138 std::vector<SdfPredicateExpression::FnArg> _funcArgs;
146 namespace SdfPredicateExpressionParser {
148 using namespace PXR_PEGTL_NAMESPACE;
150 template <
class Rule,
class Sep>
153 template <
class Rule>
using OptSpaced = pad<Rule, blank>;
160 struct NotKW : keyword<'n','o','t'> {};
161 struct AndKW : keyword<'a','n','d'> {};
162 struct OrKW : keyword<'o','r'> {};
163 struct Inf : keyword<'i','n','f'> {};
164 struct True : keyword<'t','r','u','e'> {};
165 struct False : keyword<'f','a','l','s','e'> {};
169 NotKW, AndKW, OrKW, Inf, True, False> {};
173 struct Exp : seq<one<'e','E'>, opt<one<'-','+'>>, must<Digits>> {};
174 struct Frac : if_must<one<'.'>, Digits> {};
176 opt<one<'-'>>, sor<Inf, seq<Digits, if_then_else<Frac, opt<Exp>, Exp>>>
182 template <
class Quote>
183 struct Escaped : sor<Quote, one<'\\', 'b', 'f', 'n', 'r', 't'>> {};
184 template <
class Quote>
185 struct Unescaped : minus<utf8::range<0x20, 0x10FFFF>, Quote> {};
187 template <
class Quote>
189 one<'\\'>, must<Escaped<Quote>>, Unescaped<Quote>> {};
192 if_must<one<'"'>, until<one<'"'>, StringChar<one<'"'>>>>,
193 if_must<one<'\''>, until<one<'\''>, StringChar<one<'\''>>>>
197 : sor<identifier_other,
198 one<'~', '!', '@', '#', '$', '%', '^', '&', '*', '-', '+', '=',
199 '|', '\\', '.', '?', '/'>> {};
206 PredArgFloat, PredArgInt, PredArgBool, PredArgString> {};
211 struct PredKWArg : if_must<PredKWArgPrefix, PredArgVal> {};
218 : if_then_else<list<PredParenPosArg, OptSpacedComma>,
219 opt<OptSpacedComma, list<PredKWArg, OptSpacedComma>>,
220 opt<list<PredKWArg, OptSpacedComma>>>
224 struct PredColonCall : if_must<seq<PredFuncName, one<':'>>, PredColonArgs> {};
226 PredFuncName, OptSpaced<one<'('>>,
227 must<PredParenArgs, star<blank>, one<')'>>
236 struct PredCloseGroup : one<')'> {};
243 if_must<PredOpenGroup, OptSpaced<PredExpr>, PredCloseGroup>
247 struct PredFactor : seq<opt<OptSpaced<list<NotKW, plus<blank>>>>, PredAtom> {};
248 struct PredOperator : sor<OptSpaced<AndKW>, OptSpaced<OrKW>, ImpliedAnd> {};
253 template <
class Rule>
256 template <SdfPredicateExpression::Op op>
259 template <
class Input>
277 template <
class Input>
286 template <
class Input>
295 template <
class Input>
304 template <
class Input>
306 bool outOfRange =
false;
319 template <
class Input>
328 template <
class Input>
330 std::string
const &instr = in.string();
332 if (instr ==
"inf") {
333 fval = std::numeric_limits<double>::infinity();
335 else if (instr ==
"-inf") {
336 fval = -std::numeric_limits<double>::infinity();
348 template <
class Input>
350 std::string
const &instr = in.string();
351 size_t trimAmount = 0;
352 if (instr.size() >= 2 &&
353 ((instr.front() ==
'"' && instr.back() ==
'"') ||
354 (instr.front() ==
'\'' && instr.back() ==
'\''))) {
359 instr.c_str(), instr.size(), trimAmount)));
366 template <
class Input>
372 template <SdfPredicateExpression::FnCall::Kind callKind>
375 template <
class Input>
391 #endif // PXR_USD_SDF_PREDICATE_EXPRESSION_PARSER_H
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
seq< Rule, star< at< Sep, Rule >, Sep, Rule >> LookaheadList
static SDF_API SdfPredicateExpression MakeCall(FnCall &&call)
Produce a new expression containing just a the function call call.
TF_API double TfStringToDouble(const std::string &txt)
**But if you need a result
pad< Rule, blank > OptSpaced
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
constexpr auto in(type t, int set) -> bool
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
static bool apply(Input const &in, SdfPredicateExprBuilder &builder)
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
void SetFuncArgKWName(std::string const &kw)
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
void PushCall(SdfPredicateExpression::FnCall::Kind kind)
void AddFuncArg(VtValue const &val)
PXR_NAMESPACE_OPEN_SCOPE std::string Sdf_EvalQuotedString(const char *x, size_t n, size_t trimBothSides, unsigned int *numLines=NULL)
GLuint const GLchar * name
static SDF_API SdfPredicateExpression MakeOp(Op op, SdfPredicateExpression &&left, SdfPredicateExpression &&right)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
static SDF_API SdfPredicateExpression MakeNot(SdfPredicateExpression &&right)
Produce a new expression by prepending the 'not' operator onto right.
SdfPredicateExpression Finish()
#define PXR_NAMESPACE_CLOSE_SCOPE
static void apply(Input const &in, SdfPredicateExprBuilder &builder)
**If you just want to fire and args
SdfPredicateExprBuilder()
void PushOp(SdfPredicateExpression::Op op)
OptSpaced< one<','>> OptSpacedComma
Op
Enumerant describing a subexpression operation.
TF_API int64_t TfStringToInt64(const std::string &txt, bool *outOfRange=NULL)
void SetFuncName(std::string const &name)