8#ifndef PXR_USD_SDF_PATH_PATTERN_PARSER_H
9#define PXR_USD_SDF_PATH_PATTERN_PARSER_H
13#include "pxr/usd/sdf/predicateExpressionParser.h"
14#include "pxr/base/pegtl/pegtl.hpp"
18PXR_NAMESPACE_OPEN_SCOPE
20namespace SdfPathPatternParser {
22using namespace PXR_PEGTL_NAMESPACE;
24template <
class Rule,
class Sep>
25using LookaheadList = seq<Rule, star<at<Sep, Rule>, Sep, Rule>>;
27template <
class Rule>
using OptSpaced = pad<Rule, blank>;
31struct PathPatStretch : two<'/'> {};
32struct PathPatSep : sor<PathPatStretch, one<'/'>> {};
36 OptSpaced<SdfPredicateExpressionParser::PredExpr>,
39struct PrimPathWildCard :
41 plus<sor<identifier_other, one<'?','*'>>>,
42 opt<one<'['>,plus<sor<identifier_other, one<'[',']','!','-','?','*'>>>>
45struct PropPathWildCard :
47 plus<sor<identifier_other, one<':','?','*'>>>,
48 opt<one<'['>,plus<sor<identifier_other, one<':','[',']','!','-','?','*'>>>>
51struct PrimPathPatternElemText : PrimPathWildCard {};
52struct PropPathPatternElemText : PropPathWildCard {};
54struct PrimPathPatternElem
55 : if_then_else<PrimPathPatternElemText, opt<BracedPredExpr>,
58struct PropPathPatternElem
59 : if_then_else<PropPathPatternElemText, opt<BracedPredExpr>,
62struct PathPatternElems
63 : seq<LookaheadList<PrimPathPatternElem, PathPatSep>,
64 if_must_else<one<'.'>, PropPathPatternElem, opt<PathPatStretch>>> {};
66struct AbsPathPattern : seq<PathPatSep, opt<PathPatternElems>> {};
68struct DotDot : two<'.'> {};
69struct DotDots : list<DotDot, one<'/'>> {};
71struct ReflexiveRelative : one<'.'> {};
73struct AbsoluteStart : at<one<'/'>> {};
77 if_must<AbsoluteStart, AbsPathPattern>,
78 seq<DotDots, if_then_else<PathPatSep, opt<PathPatternElems>, success>>,
80 seq<ReflexiveRelative, opt<PathPatStretch, opt<PathPatternElems>>>
87namespace SdfPathPatternActions {
89using namespace PXR_PEGTL_NAMESPACE;
91using namespace SdfPathPatternParser;
101 std::string curElemText;
107struct PathPatternAction : nothing<Rule> {};
110struct PathPatternAction<AbsoluteStart>
112 template <
class Input>
113 static void apply(Input
const &in, PatternBuilder &builder) {
119struct PathPatternAction<PathPatStretch>
121 template <
class Input>
122 static void apply(Input
const &in, PatternBuilder &builder) {
124 TF_VERIFY(builder.pattern.AppendStretchIfPossible());
131struct PathPatternAction<SdfPredicateExpressionParser::PredExpr>
132 : change_action_and_states<SdfPredicateExpressionParser::PredAction,
133 SdfPredicateExprBuilder>
135 template <
class Input>
136 static void success(Input
const &in,
137 SdfPredicateExprBuilder &predExprBuilder,
138 PatternBuilder &builder) {
139 builder.curPredExpr = predExprBuilder.Finish();
144struct PathPatternAction<PrimPathPatternElemText>
146 template <
class Input>
147 static void apply(Input
const &in, PatternBuilder &builder) {
148 builder.curElemText = in.string();
153struct PathPatternAction<PropPathPatternElemText>
155 template <
class Input>
156 static void apply(Input
const &in, PatternBuilder &builder) {
157 builder.curElemText = in.string();
162struct PathPatternAction<PrimPathPatternElem>
164 template <
class Input>
165 static void apply(Input
const &in, PatternBuilder &builder) {
166 builder.pattern.AppendChild(builder.curElemText, builder.curPredExpr);
167 builder.curElemText.clear();
173struct PathPatternAction<PropPathPatternElem>
175 template <
class Input>
176 static void apply(Input
const &in, PatternBuilder &builder) {
177 builder.pattern.AppendProperty(builder.curElemText,
178 builder.curPredExpr);
179 builder.curElemText.clear();
185struct PathPatternAction<ReflexiveRelative>
187 template <
class Input>
188 static void apply(Input
const &in, PatternBuilder &builder) {
194struct PathPatternAction<DotDot>
196 template <
class Input>
197 static void apply(Input
const &in, PatternBuilder &builder) {
198 builder.pattern.AppendChild(
"..");
204PXR_NAMESPACE_CLOSE_SCOPE
static SDF_API const SdfPath & AbsoluteRootPath()
The absolute path representing the top of the namespace hierarchy.
static SDF_API const SdfPath & ReflexiveRelativePath()
The relative path representing "self".
Objects of this class represent SdfPath matching patterns, consisting of an SdfPath prefix followed b...
Represents a logical expression syntax tree consisting of predicate function calls joined by the logi...
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.