VTK  9.3.0
vtkMotionFXCFGGrammar.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
3 #ifndef vtkMotionFXCFGGrammar_h
4 #define vtkMotionFXCFGGrammar_h
5 
6 // Internal header used by vtkMotionFXCFGReader.
7 // We define the various grammars here rather than clobbering the
8 // vtkMotionFXCFGReader.cxx.
9 
10 #include <vtk_pegtl.h>
11 
12 // for debugging
13 // clang-format off
14 #include VTK_PEGTL(pegtl/contrib/tracer.hpp)
15 // clang-format on
16 
17 namespace MotionFX
18 {
19 using namespace tao::pegtl;
20 
21 //-----------------------------------------------------------------------------
22 // lets define some common rules here.
23 namespace Common
24 {
25 VTK_ABI_NAMESPACE_BEGIN
26 struct Sign : sor<one<'+'>, one<'-'>>
27 {
28 };
29 struct Exponent : seq<sor<one<'e'>, one<'E'>>, opt<Sign>, plus<digit>>
30 {
31 };
32 struct Number
33  : seq<opt<Sign>,
34  sor<seq<plus<digit>, one<'.'>, star<digit>>, seq<one<'.'>, plus<digit>>, plus<digit>>,
35  opt<Exponent>>
36 {
37 };
38 
39 // delimiter for columns in files such as the position files
40 // this can be ',' separated by optional spaces or just spaces
41 struct Delimiter : sor<seq<star<space>, one<','>, star<space>>, plus<space>>
42 {
43 };
44 VTK_ABI_NAMESPACE_END
45 } // namespace Common
46 
47 //-----------------------------------------------------------------------------
48 // rules for parsing a position file in legacy format, also called old rot.vel.
49 // format.
50 namespace LegacyPositionFile
51 {
52 VTK_ABI_NAMESPACE_BEGIN
53 using namespace Common;
54 
55 // format: time CoMx CoMy CoMz Fx Fy Fz
56 struct Row
57  : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
58  Number, Delimiter, Number, Delimiter, Number, star<space>>
59 {
60 };
61 
62 struct Grammar : star<Row>
63 {
64 };
65 VTK_ABI_NAMESPACE_END
66 } // namespace LegacyPositionFile
67 
68 //-----------------------------------------------------------------------------
69 // rules for parsing a position file in orientations formation.
70 namespace OrientationsPositionFile
71 {
72 VTK_ABI_NAMESPACE_BEGIN
73 using namespace Common;
74 
75 // format: time CoMx CoMy CoMz cosX cosY cosZ Orientation (radians)
76 struct Row
77  : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
78  Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, star<space>>
79 {
80 };
81 
82 struct Grammar : star<Row>
83 {
84 };
85 VTK_ABI_NAMESPACE_END
86 } // namespace OrientationsPositionFile
87 
88 //-----------------------------------------------------------------------------
89 // rules for parsing a universal transform file
90 namespace UniversalTransformRow
91 {
92 VTK_ABI_NAMESPACE_BEGIN
93 using namespace Common;
94 
95 // format: time
96 // trnvecx trnvecy trnvecz
97 // rotcntrx rotcntry rotcntrz
98 // quat0 quat1 quat2 quat3
99 // scalex scaley scalez
100 struct Row
101  : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
102  Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
103  Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number,
104  star<space>>
105 {
106 };
107 
108 struct Grammar : star<Row>
109 {
110 };
111 VTK_ABI_NAMESPACE_END
112 } // namespace UniversalTransformRow
113 
114 //-----------------------------------------------------------------------------
115 // rules to parse CFG file.
116 namespace CFG
117 {
118 VTK_ABI_NAMESPACE_BEGIN
119 using namespace Common;
120 
121 // Rule that matches a Comment. Consume everything on the line following a ';'
122 struct Comment : seq<string<';'>, until<eolf>>
123 {
124 };
125 
126 struct WS_Required : sor<Comment, eol, plus<space>>
127 {
128 };
129 struct WS : star<WS_Required>
130 {
131 };
132 
133 struct Value : plus<not_one<';', '}', '\r', '\n'>>
134 {
135 };
136 
137 struct ParameterName : identifier
138 {
139 };
140 struct Statement : seq<ParameterName, WS_Required, Value>
141 {
142 };
143 struct StatementOther : seq<ParameterName, WS_Required, plus<not_one<'}', '{', ';'>>>
144 {
145 };
146 
147 struct Motion : seq<TAO_PEGTL_STRING("motion"), WS, one<'{'>, WS, list<Statement, WS>, WS, one<'}'>>
148 {
149 };
150 struct Motions : seq<TAO_PEGTL_STRING("motions"), WS, one<'{'>, WS, list<Motion, WS>, WS, one<'}'>>
151 {
152 };
153 
154 struct OtherNonNested : seq<identifier, WS, one<'{'>, WS, list<StatementOther, WS>, WS, one<'}'>>
155 {
156 };
157 
159  : seq<identifier, WS, one<'{'>, WS, list<sor<OtherNonNested, StatementOther>, WS>, WS, one<'}'>>
160 {
161 };
162 
163 struct Lines : sor<Comment, space, Motions, OtherNonNested, OtherNested>
164 {
165 };
166 
167 struct Grammar : star<Lines>
168 {
169 };
170 
171 VTK_ABI_NAMESPACE_END
172 } // namespace CFG
173 } // namespace MotionFX
174 
175 #endif
176 // VTK-HeaderTest-Exclude: vtkMotionFXCFGGrammar.h