Skip to content

Commit

Permalink
Use pgtl ns inside anonymous ns, to try and clear up errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
furby-tm committed Aug 6, 2024
1 parent e5d2220 commit d088dba
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions Sources/Sdf/variableExpressionParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PXR_NAMESPACE_OPEN_SCOPE

namespace {

using namespace PXR_PEGTL_NAMESPACE;

namespace Impl = Sdf_VariableExpressionImpl;

// Node creators -----------------------------------------------
Expand Down Expand Up @@ -281,13 +283,13 @@ void _ThrowParseError(const Input &in, const std::string &msg)
// missing "}". This is because it recognizes everything up to the
// illegal character as the variable and expects to find the
// closing "}" after it. It'd be nice to fix this.
struct VariableStart : PXR_PEGTL_NAMESPACE::ascii::string<'$', '{'> {};
struct VariableStart : string<'$', '{'> {};

struct VariableEnd : PXR_PEGTL_NAMESPACE::ascii::string<'}'> {};
struct VariableEnd : string<'}'> {};

template<class C> struct VariableName : identifier {};

template<class C> struct VariableImpl : PXR_PEGTL_NAMESPACE::internal::if_must<VariableStart, VariableName<C>, VariableEnd> {
template<class C> struct VariableImpl : if_must<VariableStart, VariableName<C>, VariableEnd> {
using Name = VariableName<C>;
};

Expand All @@ -304,23 +306,23 @@ template<char QuoteChar> struct QuotedStringEscapedChar : one<'`', '$', '\\', Qu

// Sequence of allowed characters in a quoted string.
template<char QuoteChar>
struct QuotedStringChars : PXR_PEGTL_NAMESPACE::internal::plus<PXR_PEGTL_NAMESPACE::internal::sor<
struct QuotedStringChars : plus<sor<
// An escaped character.
PXR_PEGTL_NAMESPACE::internal::seq<one<'\\'>, QuotedStringEscapedChar<QuoteChar>>,
seq<one<'\\'>, QuotedStringEscapedChar<QuoteChar>>,
// Any other characters that aren't the start of a stage
// variable or the quote character, since those are handled
// by different rules.
PXR_PEGTL_NAMESPACE::internal::seq<PXR_PEGTL_NAMESPACE::internal::not_at<PXR_PEGTL_NAMESPACE::internal::sor<VariableStart, one<QuoteChar>>>, any>>> {};
seq<not_at<sor<VariableStart, one<QuoteChar>>>, any>>> {};

template<char QuoteChar> struct QuotedStringStart : PXR_PEGTL_NAMESPACE::ascii::string<QuoteChar> {};
template<char QuoteChar> struct QuotedStringStart : string<QuoteChar> {};

template<char QuoteChar> struct QuotedStringEnd : PXR_PEGTL_NAMESPACE::ascii::string<QuoteChar> {};
template<char QuoteChar> struct QuotedStringEnd : string<QuoteChar> {};

template<char QuoteChar>
struct QuotedStringBody : PXR_PEGTL_NAMESPACE::internal::star<PXR_PEGTL_NAMESPACE::internal::sor<QuotedStringVariable, QuotedStringChars<QuoteChar>>> {};
struct QuotedStringBody : star<sor<QuotedStringVariable, QuotedStringChars<QuoteChar>>> {};

template<char QuoteChar>
struct QuotedString : PXR_PEGTL_NAMESPACE::internal::if_must<QuotedStringStart<QuoteChar>,
struct QuotedString : if_must<QuotedStringStart<QuoteChar>,
QuotedStringBody<QuoteChar>,
QuotedStringEnd<QuoteChar>> {
using Start = QuotedStringStart<QuoteChar>;
Expand All @@ -333,23 +335,23 @@ using SingleQuotedString = QuotedString<'\''>;

// ----------------------------------------

struct Integer : PXR_PEGTL_NAMESPACE::internal::seq<PXR_PEGTL_NAMESPACE::internal::opt<one<'-'>>, PXR_PEGTL_NAMESPACE::internal::plus<ascii::digit>> {};
struct Integer : seq<opt<one<'-'>>, plus<ascii::digit>> {};

// ----------------------------------------

// We allow "True", "true", "False", "false" because these
// are the representations used in the two primary languages supported
// by USD -- C++ and Python -- and that correspondence may make it easier
// for users working in those languages while writing expressions.
struct BooleanTrue : PXR_PEGTL_NAMESPACE::internal::sor<PXR_PEGTL_KEYWORD("True"), PXR_PEGTL_KEYWORD("true")> {};
struct BooleanTrue : sor<PXR_PEGTL_KEYWORD("True"), PXR_PEGTL_KEYWORD("true")> {};

struct BooleanFalse : PXR_PEGTL_NAMESPACE::internal::sor<PXR_PEGTL_KEYWORD("False"), PXR_PEGTL_KEYWORD("false")> {};
struct BooleanFalse : sor<PXR_PEGTL_KEYWORD("False"), PXR_PEGTL_KEYWORD("false")> {};

struct Boolean : PXR_PEGTL_NAMESPACE::internal::sor<BooleanTrue, BooleanFalse> {};
struct Boolean : sor<BooleanTrue, BooleanFalse> {};

// ----------------------------------------

struct None : PXR_PEGTL_NAMESPACE::internal::sor<PXR_PEGTL_KEYWORD("None"), PXR_PEGTL_KEYWORD("none")> {};
struct None : sor<PXR_PEGTL_KEYWORD("None"), PXR_PEGTL_KEYWORD("none")> {};

// ----------------------------------------

Expand All @@ -358,9 +360,9 @@ struct ExpressionBody;

struct FunctionName : identifier {};

struct FunctionArgumentStart : PXR_PEGTL_NAMESPACE::internal::pad<one<'('>, one<' '>> {};
struct FunctionArgumentStart : pad<one<'('>, one<' '>> {};

struct FunctionArgumentEnd : PXR_PEGTL_NAMESPACE::internal::pad<one<')'>, one<' '>> {};
struct FunctionArgumentEnd : pad<one<')'>, one<' '>> {};

// A function argument can be any valid expression. We can't directly
// derive from ExpressionBody because doing so would require ExpressionBody
Expand All @@ -371,15 +373,15 @@ template<class Base> struct FunctionArgumentWrapper : public Base {};
using FunctionArgument = FunctionArgumentWrapper<ExpressionBody>;

// Function arguments are zero or more comma-separated arguments.
struct FunctionArguments : PXR_PEGTL_NAMESPACE::internal::sor<list<FunctionArgument, one<','>, one<' '>>, PXR_PEGTL_NAMESPACE::internal::star<one<' '>>> {};
struct FunctionArguments : sor<list<FunctionArgument, one<','>, one<' '>>, star<one<' '>>> {};

struct Function
: PXR_PEGTL_NAMESPACE::internal::if_must<PXR_PEGTL_NAMESPACE::internal::seq<FunctionName, FunctionArgumentStart>, FunctionArguments, FunctionArgumentEnd> {};
: if_must<seq<FunctionName, FunctionArgumentStart>, FunctionArguments, FunctionArgumentEnd> {};

// ----------------------------------------

struct ScalarExpression
: PXR_PEGTL_NAMESPACE::internal::sor<Variable, DoubleQuotedString, SingleQuotedString, Integer, Boolean, None, Function> {};
: sor<Variable, DoubleQuotedString, SingleQuotedString, Integer, Boolean, None, Function> {};

// ----------------------------------------

Expand All @@ -389,19 +391,19 @@ struct ListEnd : one<']'> {};

struct ListElement : public ScalarExpression {};

struct ListElements : PXR_PEGTL_NAMESPACE::internal::sor<list<ListElement, one<','>, one<' '>>, PXR_PEGTL_NAMESPACE::internal::star<one<' '>>> {};
struct ListElements : sor<list<ListElement, one<','>, one<' '>>, star<one<' '>>> {};

struct ListExpression : PXR_PEGTL_NAMESPACE::internal::if_must<ListStart, ListElements, ListEnd> {};
struct ListExpression : if_must<ListStart, ListElements, ListEnd> {};

// ----------------------------------------

struct ExpressionStart : PXR_PEGTL_NAMESPACE::ascii::string<'`'> {};
struct ExpressionStart : string<'`'> {};

struct ExpressionEnd : PXR_PEGTL_NAMESPACE::ascii::string<'`'> {};
struct ExpressionEnd : string<'`'> {};

struct ExpressionBody : PXR_PEGTL_NAMESPACE::internal::sor<ScalarExpression, ListExpression> {};
struct ExpressionBody : sor<ScalarExpression, ListExpression> {};

struct Expression : PXR_PEGTL_NAMESPACE::internal::must<ExpressionStart, ExpressionBody, ExpressionEnd> {};
struct Expression : must<ExpressionStart, ExpressionBody, ExpressionEnd> {};

// Parser actions ---------------------------------------------
// Objects that define the actions to take when a parsing rule
Expand Down

0 comments on commit d088dba

Please sign in to comment.