VTK  9.0.3
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 
29 namespace MotionFX
30 {
31 using namespace tao::pegtl;
32 
33 //-----------------------------------------------------------------------------
34 // lets define some common rules here.
35 namespace Common
36 {
37 struct Sign : sor<one<'+'>, one<'-'> >
38 {
39 };
40 struct Exponent : seq<sor<one<'e'>, one<'E'> >, opt<Sign>, plus<digit> >
41 {
42 };
43 struct 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
52 struct 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.
60 namespace LegacyPositionFile
61 {
62 using namespace Common;
63 
64 // format: time CoMx CoMy CoMz Fx Fy Fz
65 struct Row
66  : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number, Delimiter,
67  Number, Delimiter, Number, Delimiter, Number, star<space> >
68 {
69 };
70 
71 struct Grammar : star<Row>
72 {
73 };
74 } // namespace LegacyPositionFile
75 
76 //-----------------------------------------------------------------------------
77 // rules for parsing a position file in orientations formation.
78 namespace OrientationsPositionFile
79 {
80 using namespace Common;
81 
82 // format: time CoMx CoMy CoMz cosX cosY cosZ Orientation (radians)
83 struct 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 
89 struct Grammar : star<Row>
90 {
91 };
92 } // namespace OrientationsPositionFile
93 
94 //-----------------------------------------------------------------------------
95 // rules to parse CFG file.
96 namespace CFG
97 {
98 using namespace Common;
99 
100 // Rule that matches a Comment. Consume everything on the line following a ';'
101 struct Comment : seq<string<';'>, until<eolf> >
102 {
103 };
104 
105 struct WS_Required : sor<Comment, eol, plus<space> >
106 {
107 };
108 struct WS : star<WS_Required>
109 {
110 };
111 
112 struct Value : plus<not_one<';', '}', '\r', '\n'> >
113 {
114 };
115 
116 struct ParameterName : identifier
117 {
118 };
119 struct Statement : seq<ParameterName, WS_Required, Value>
120 {
121 };
122 struct StatementOther : seq<ParameterName, WS_Required, plus<not_one<'}', '{', ';'> > >
123 {
124 };
125 
126 struct Motion
127  : seq<TAO_PEGTL_STRING("motion"), WS, one<'{'>, WS, list<Statement, WS>, WS, one<'}'> >
128 {
129 };
130 struct Motions : seq<TAO_PEGTL_STRING("motions"), WS, one<'{'>, WS, list<Motion, WS>, WS, one<'}'> >
131 {
132 };
133 
134 struct OtherNonNested : seq<identifier, WS, one<'{'>, WS, list<StatementOther, WS>, WS, one<'}'> >
135 {
136 };
137 
139  : seq<identifier, WS, one<'{'>, WS, list<sor<OtherNonNested, StatementOther>, WS>, WS, one<'}'> >
140 {
141 };
142 
143 struct Lines : sor<Comment, space, Motions, OtherNonNested, OtherNested>
144 {
145 };
146 
147 struct Grammar : star<Lines>
148 {
149 };
150 
151 } // namespace CFG
152 
153 } // namespace MotionFX
154 
155 #endif
156 // VTK-HeaderTest-Exclude: vtkMotionFXCFGGrammar.h