VTK  9.3.20240425
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
17namespace MotionFX
18{
19using namespace tao::pegtl;
20
21//-----------------------------------------------------------------------------
22// lets define some common rules here.
23namespace Common
24{
25VTK_ABI_NAMESPACE_BEGIN
26struct Sign : sor<one<'+'>, one<'-'>>
27{
28};
29struct Exponent : seq<sor<one<'e'>, one<'E'>>, opt<Sign>, plus<digit>>
30{
31};
32struct 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
41struct Delimiter : sor<seq<star<space>, one<','>, star<space>>, plus<space>>
42{
43};
44VTK_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.
50namespace LegacyPositionFile
51{
52VTK_ABI_NAMESPACE_BEGIN
53using namespace Common;
54
55// format: time CoMx CoMy CoMz Fx Fy Fz
56struct Row
57 : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
58 Number, Delimiter, Number, Delimiter, Number, star<space>>
59{
60};
61
62struct Grammar : star<Row>
63{
64};
65VTK_ABI_NAMESPACE_END
66} // namespace LegacyPositionFile
67
68//-----------------------------------------------------------------------------
69// rules for parsing a position file in orientations formation.
70namespace OrientationsPositionFile
71{
72VTK_ABI_NAMESPACE_BEGIN
73using namespace Common;
74
75// format: time CoMx CoMy CoMz cosX cosY cosZ Orientation (radians)
76struct 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
82struct Grammar : star<Row>
83{
84};
85VTK_ABI_NAMESPACE_END
86} // namespace OrientationsPositionFile
87
88//-----------------------------------------------------------------------------
89// rules for parsing a universal transform file
90namespace UniversalTransformRow
91{
92VTK_ABI_NAMESPACE_BEGIN
93using namespace Common;
94
95// format: time
96// trnvecx trnvecy trnvecz
97// rotcntrx rotcntry rotcntrz
98// quat0 quat1 quat2 quat3
99// scalex scaley scalez
100struct 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
108struct Grammar : star<Row>
109{
110};
111VTK_ABI_NAMESPACE_END
112} // namespace UniversalTransformRow
113
114//-----------------------------------------------------------------------------
115// rules to parse CFG file.
116namespace CFG
117{
118VTK_ABI_NAMESPACE_BEGIN
119using namespace Common;
120
121// Rule that matches a Comment. Consume everything on the line following a ';'
122struct Comment : seq<string<';'>, until<eolf>>
123{
124};
125
126struct WS_Required : sor<Comment, eol, plus<space>>
127{
128};
129struct WS : star<WS_Required>
130{
131};
132
133struct Value : plus<not_one<';', '}', '\r', '\n'>>
134{
135};
136
137struct ParameterName : identifier
138{
139};
140struct Statement : seq<ParameterName, WS_Required, Value>
141{
142};
143struct StatementOther : seq<ParameterName, WS_Required, plus<not_one<'}', '{', ';'>>>
144{
145};
146
147struct Motion : seq<TAO_PEGTL_STRING("motion"), WS, one<'{'>, WS, list<Statement, WS>, WS, one<'}'>>
148{
149};
150struct Motions : seq<TAO_PEGTL_STRING("motions"), WS, one<'{'>, WS, list<Motion, WS>, WS, one<'}'>>
151{
152};
153
154struct 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
163struct Lines : sor<Comment, space, Motions, OtherNonNested, OtherNested>
164{
165};
166
167struct Grammar : star<Lines>
168{
169};
170
171VTK_ABI_NAMESPACE_END
172} // namespace CFG
173} // namespace MotionFX
174
175#endif
176// VTK-HeaderTest-Exclude: vtkMotionFXCFGGrammar.h