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>
using OptSpaced = pad<Rule, blank>;
28struct PathPatStretch : two<'/'> {};
29struct PathPatSep : sor<PathPatStretch, one<'/'>> {};
32struct PredExprClose : one<'}'> {};
33struct BracketClassClose : one<']'> {};
39 OptSpaced<SdfPredicateExpressionParser::PredExpr>,
45 plus<sor<identifier_other, one<'!','-','?','*'>>>,
46 BracketClassClose> {};
48struct PrimPathWildCard :
49 plus<sor<BracketClass, identifier_other, one<'?','*'>>> {};
51struct PropPathWildCard :
52 plus<sor<BracketClass, identifier_other, one<':','?','*'>>> {};
54struct PrimPathPatternElemText : PrimPathWildCard {};
55struct PropPathPatternElemText : PropPathWildCard {};
57struct PrimPathPatternElem
58 : if_then_else<PrimPathPatternElemText, opt<BracedPredExpr>,
61struct PropPathPatternElem
62 : if_then_else<PropPathPatternElemText, opt<BracedPredExpr>,
67struct PatSepSlash : seq<one<'/'>, not_at<one<'/'>>> {};
70struct PrimPatStep : if_must<PatSepSlash, PrimPathPatternElem> {};
77struct StretchStep : seq<
78 at<seq<PathPatStretch, PrimPathPatternElem>>,
80 PrimPathPatternElem> {};
82struct PathPatternElems
83 : seq<PrimPathPatternElem,
84 star<sor<StretchStep, PrimPatStep>>,
85 if_must_else<one<'.'>, PropPathPatternElem, opt<PathPatStretch>>> {};
87struct AbsPathPattern : seq<PathPatSep, opt<PathPatternElems>> {};
89struct DotDot : two<'.'> {};
90struct DotDots : list<DotDot, one<'/'>> {};
92struct ReflexiveRelative : one<'.'> {};
94struct AbsoluteStart : at<one<'/'>> {};
99struct DotDotsStep : if_must<PatSepSlash, PathPatternElems> {};
100struct DotDotsStretchTail : seq<PathPatStretch, opt<PathPatternElems>> {};
104 if_must<AbsoluteStart, AbsPathPattern>,
105 seq<DotDots, opt<sor<DotDotsStretchTail, DotDotsStep>>>,
107 seq<ReflexiveRelative, opt<PathPatStretch, opt<PathPatternElems>>>
123struct Errors : SdfPredicateExpressionParser::Errors<Rule> {};
125#define PARSE_ERROR(rule, msg) \
126 template <> struct Errors<rule> \
127 : SdfPredicateExpressionParser::Errors<rule> { \
128 template <class Input, class... States> \
129 [[noreturn]] static void raise(Input const &in, States &&...) { \
130 throw parse_error(msg, in); \
134PARSE_ERROR(PrimPathPatternElem,
"expected path pattern element");
135PARSE_ERROR(PathPatternElems,
"expected path pattern element after '/'");
136PARSE_ERROR(PropPathPatternElem,
"expected property pattern element after '.'");
137PARSE_ERROR(PredExprClose,
"expected '}' to close predicate expression");
138PARSE_ERROR(BracketClassClose,
"expected ']' to close bracket class");
145namespace SdfPathPatternActions {
147using namespace PXR_PEGTL_NAMESPACE;
149using namespace SdfPathPatternParser;
159 std::string curElemText;
165struct PathPatternAction : nothing<Rule> {};
168struct PathPatternAction<AbsoluteStart>
170 template <
class Input>
171 static void apply(Input
const &in, PatternBuilder &builder) {
177struct PathPatternAction<PathPatStretch>
179 template <
class Input>
180 static void apply(Input
const &in, PatternBuilder &builder) {
182 TF_VERIFY(builder.pattern.AppendStretchIfPossible());
189struct PathPatternAction<SdfPredicateExpressionParser::PredExpr>
190 : change_action_and_states<SdfPredicateExpressionParser::PredAction,
191 SdfPredicateExprBuilder>
193 template <
class Input>
194 static void success(Input
const &in,
195 SdfPredicateExprBuilder &predExprBuilder,
196 PatternBuilder &builder) {
197 builder.curPredExpr = predExprBuilder.Finish();
202struct PathPatternAction<PrimPathPatternElemText>
204 template <
class Input>
205 static void apply(Input
const &in, PatternBuilder &builder) {
206 builder.curElemText = in.string();
211struct PathPatternAction<PropPathPatternElemText>
213 template <
class Input>
214 static void apply(Input
const &in, PatternBuilder &builder) {
215 builder.curElemText = in.string();
220struct PathPatternAction<PrimPathPatternElem>
222 template <
class Input>
223 static void apply(Input
const &in, PatternBuilder &builder) {
224 builder.pattern.AppendChild(builder.curElemText, builder.curPredExpr);
225 builder.curElemText.clear();
231struct PathPatternAction<PropPathPatternElem>
233 template <
class Input>
234 static void apply(Input
const &in, PatternBuilder &builder) {
235 builder.pattern.AppendProperty(builder.curElemText,
236 builder.curPredExpr);
237 builder.curElemText.clear();
243struct PathPatternAction<ReflexiveRelative>
245 template <
class Input>
246 static void apply(Input
const &in, PatternBuilder &builder) {
252struct PathPatternAction<DotDot>
254 template <
class Input>
255 static void apply(Input
const &in, PatternBuilder &builder) {
256 builder.pattern.AppendChild(
"..");
262PXR_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.