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