Skip to content

Commit d2f309c

Browse files
erslavinpixar-oss
authored andcommitted
Spline Parser Rule Consistency
- Modified SplinePostShaping rule to make sure: - there is a TokenSeparator (at least a space with allowance for cpp multi line comments with padding) between KeywordPost and SplineInterpMode (To avoid things like postcurve) - Make sure to have internal padding between SplineInterpMode and SplineTangen (to avoid things like curve(1,2)) - Aligned comments above rules to better represent rule intent - Added additional tests for incorrect spline parsing rules + additional tests to justify some correct parsing rules. Closes PixarAnimationStudios#3562 (Internal change: 2360314)
1 parent 23166ff commit d2f309c

File tree

7 files changed

+99
-13
lines changed

7 files changed

+99
-13
lines changed

pxr/usd/sdf/testenv/testSdfParsing.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ def test_Basic(self):
4747
# This will mean that your new test runs first and you can spot
4848
# failures much quicker.
4949
testFiles = '''
50+
225_multiline_with_SplineKnotParamList.sdf
51+
224_spline_post_shaping_with_comment.sdf
52+
223_bad_spline_post_shaping_spacing.sdf
5053
222_dict_key_control_characters.sdf
5154
221_bad_spline_type.sdf
5255
220_splines.sdf
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#sdf 1.4.32
2+
3+
def Xform "Prim2"
4+
{
5+
custom double myAttr = 17.12
6+
double myAttr.spline = {
7+
bezier,
8+
pre: linear,
9+
post: sloped(0.57),
10+
loop: (15, 25, 0, 2, 11.7),
11+
7: 5.5 & 7.21; post held,
12+
15: 8.18; post curve (2.49, 1.17); { string comment = "climb!" },
13+
14+
# the post shaping statement below has a curve interpolation mode
15+
# that does not have a space between the mode and the left paren
16+
20: 14.72; pre (3.77, -1.4); post curve(1.1, -1.4),
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#sdf 1.4.32
2+
3+
def Xform "Prim2"
4+
{
5+
custom double myAttr = 17.12
6+
double myAttr.spline = {
7+
bezier,
8+
pre: linear,
9+
post: sloped(0.57),
10+
loop: (15, 25, 0, 2, 11.7),
11+
7: 5.5 & 7.21; post held,
12+
15: 8.18; post curve (2.49, 1.17); { string comment = "climb!" },
13+
14+
# the post shaping statement below has a curve interpolation mode
15+
# that does not have a space between the mode and the left paren
16+
20: 14.72; pre (3.77, -1.4); post curve/*comment should be treated as a whitepace*/(1.1, -1.4),
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#sdf 1.4.32
2+
3+
def Xform "Prim2"
4+
{
5+
custom double myAttr = 17.12
6+
double myAttr.spline = {
7+
bezier,
8+
pre: linear,
9+
post: sloped(0.57),
10+
loop: (15, 25, 0, 2, 11.7),
11+
7: 5.5 & 7.21; post held,
12+
# try multiline padding with SplineKnotParamList
13+
15: 8.18; post curve (2.49, 1.17);
14+
{ string comment = "climb!" },
15+
}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#sdf 1.4.32
2+
3+
def Xform "Prim2"
4+
{
5+
custom double myAttr = 17.12
6+
double myAttr.spline = {
7+
bezier,
8+
pre: linear,
9+
post: sloped(0.57),
10+
loop: (15, 25, 0, 2, 11.7),
11+
7: 5.5 & 7.21; pre (0, 0); post held,
12+
15: 8.18; post curve (2.49, 1.17); { string comment = "climb!" },
13+
20: 14.72; pre (3.77, -1.4); post curve (1.1, -1.4),
14+
}
15+
}
16+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#sdf 1.4.32
2+
3+
def Xform "Prim2"
4+
{
5+
custom double myAttr = 17.12
6+
double myAttr.spline = {
7+
pre: linear,
8+
post: sloped(0.57),
9+
loop: (15, 25, 0, 2, 11.7),
10+
7: 5.5 & 7.21; pre (0, 0); post held,
11+
15: 8.18; post curve (2.49, 1.17); { string comment = "climb!" },
12+
}
13+
}
14+

pxr/usd/sdf/textFileFormatParser.h

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -693,10 +693,10 @@ struct SplineCurveTypeItem : PEGTL_NS::sor<
693693
KeywordBezier> {};
694694

695695
struct SlopeValue : Number {};
696-
// SplineExtrapolationType = NONE / HELD / LINEAR /
697-
// SLOPED '(' (TokenSeparator)? SloveValue (TokenSeparator)? ')' /
698-
// LOOP TokenSeparator REPEAT / LOOP TokenSeparator RESET /
699-
// LOOP TokenSeparator OSCILLATE
696+
// SplineExtrapolationType = NONE / HELD / LINEAR /
697+
// SLOPED (InlinePadding)* '(' (InlinePadding)* SlopeValue (InlinePadding)* ')' /
698+
// LOOP TokenSeparator REPEAT / LOOP TokenSeparator RESET / LOOP
699+
// TokenSeparator OSCILLATE
700700
struct SplineExtrapolationType : PEGTL_NS::sor<
701701
KeywordNone_LC,
702702
KeywordHeld,
@@ -710,14 +710,14 @@ struct SplineExtrapolationType : PEGTL_NS::sor<
710710
PEGTL_NS::seq<KeywordLoop, TokenSeparator, KeywordOscillate>> {};
711711

712712
// SplinePreExtrapItem = pre (TokenSeparator)? Colon (TokenSeparator)?
713-
// SplineExtrapolation
713+
// SplineExtrapolationType
714714
struct SplinePreExtrapItem : PEGTL_NS::seq<
715715
KeywordPre,
716716
PEGTL_NS::pad<Colon, InlinePadding>,
717717
SplineExtrapolationType> {};
718718

719719
// SplinePostExtrapItem = post (TokenSeparator)? Colon (TokenSeparator)?
720-
// SplineExtrapolation
720+
// SplineExtrapolationType
721721
struct SplinePostExtrapItem : PEGTL_NS::seq<
722722
KeywordPost,
723723
PEGTL_NS::pad<Colon, InlinePadding>,
@@ -789,16 +789,17 @@ struct SplineInterpMode : PEGTL_NS::sor<
789789

790790
// SplinePreTan = pre TokenSeparator SplineTangent
791791
struct SplinePreTan : PEGTL_NS::seq<
792-
KeywordPre,
792+
KeywordPre,
793793
TokenSeparator,
794794
SplineTangent> {};
795795

796796
// SplinePostShaping = post (TokenSeparator)? SplineInterpMode (TokenSeparator)?
797797
// (SplineTangent)?
798798
struct SplinePostShaping : PEGTL_NS::seq<
799799
KeywordPost,
800-
PEGTL_NS::pad<SplineInterpMode, InlinePadding>,
801-
PEGTL_NS::opt<SplineTangent>> {};
800+
TokenSeparator,
801+
SplineInterpMode,
802+
PEGTL_NS::opt<InlinePadding, SplineTangent>> {};
802803

803804
// SplineKnotParam = SplinePreTan / SplinePostShaping / DictionaryValue
804805
struct SplineKnotParam : PEGTL_NS::sor<
@@ -815,7 +816,7 @@ struct SplineKnotParamList : PEGTL_NS::opt<
815816
PEGTL_NS::seq<
816817
PEGTL_NS::pad<
817818
StatementSequenceOf<SplineKnotParam>, InlinePadding>,
818-
PEGTL_NS::not_at<StatementSeparator>>>> {};
819+
PEGTL_NS::not_at<SplineKnotParamSeparator>>>> {};
819820

820821
struct SplineKnotValue : Number {};
821822
struct SplineKnotPreValue : Number {};
@@ -826,8 +827,8 @@ struct SplineKnotValueWithoutPreValue : PEGTL_NS::seq<
826827
SplineKnotValue,
827828
PEGTL_NS::pad<PEGTL_NS::not_at<SplineKnotPreValueSeparator>,
828829
InlinePadding>> {};
829-
// SplineKnotValueWithPreValue = SplineKnotPreValue (TokenSeparator)?
830-
// SplineKnotPreValueSeparator SplineKnotValue
830+
// SplineKnotValueWithPreValue = SplineKnotPreValue InlinePadding
831+
// SplineKnotPreValueSeparator InlinePadding SplineKnotValue
831832
struct SplineKnotValueWithPreValue : PEGTL_NS::seq<
832833
SplineKnotPreValue,
833834
PEGTL_NS::pad<SplineKnotPreValueSeparator, InlinePadding>,
@@ -857,7 +858,7 @@ struct SplineItem : PEGTL_NS::sor<
857858
SplineLoopItem,
858859
SplineKnotItem> {};
859860

860-
// SplineValue = { (TokenSeparator)? (SplineItem (TokenSeparator)?)* }
861+
// SplineValue = { (MultilinePadding)? (SplineItem (MultilinePadding)?)* }
861862
struct SplineValue : PEGTL_NS::if_must<
862863
LeftBrace,
863864
PEGTL_NS::pad<ListOf<SplineItem>, MultilinePadding>,

0 commit comments

Comments
 (0)