VTK
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 #include <vtkpegtl/include/tao/pegtl/contrib/tracer.hpp>
26 
27 namespace MotionFX
28 {
29 using namespace tao::pegtl;
30 
31 //-----------------------------------------------------------------------------
32 // lets define some common rules here.
33 namespace Common
34 {
35 struct Sign : sor<one<'+'>, one<'-'>> {};
36 struct Exponent : seq<sor<one<'e'>, one<'E'> >, opt<Sign>, plus<digit>> {};
37 struct Number : seq<opt<Sign>,
38  sor<seq<plus<digit>, one<'.'>, star<digit>>,
39  seq<one<'.'>, plus<digit> >, plus<digit>>,
40  opt<Exponent>> {};
41 
42 // delimiter for columns in files such as the position files
43 // this can be ',' separated by optional spaces or just spaces
44 struct Delimiter : sor<
45  seq<star<space>, one<','>, star<space>>,
46  plus<space> > {};
47 } // namespace Common
48 
49 //-----------------------------------------------------------------------------
50 // rules for parsing a position file in legacy format, also called old rot.vel.
51 // format.
52 namespace LegacyPositionFile
53 {
54 using namespace Common;
55 
56 // format: time CoMx CoMy CoMz Fx Fy Fz
57 struct Row
58  : seq<star<space>, Number, Delimiter, Number, Delimiter, Number, Delimiter, Number,
59  Delimiter, Number, Delimiter, Number, Delimiter, Number, star<space>> {};
60 
61 struct Grammar : star<Row> {};
62 } // namespace LegacyPositionFile
63 
64 //-----------------------------------------------------------------------------
65 // rules for parsing a position file in orientations formation.
66 namespace OrientationsPositionFile
67 {
68 using namespace Common;
69 
70 // format: time CoMx CoMy CoMz cosX cosY cosZ Orientation (radians)
71 struct Row :
72  seq<star<space>, Number, Delimiter, Number, Delimiter, Number,
73  Delimiter, Number, Delimiter, Number, Delimiter, Number,
74  Delimiter, Number, Delimiter, Number, star<space>> {};
75 
76 struct Grammar : star<Row> {};
77 } // namespace OrientationsPositionFile
78 
79 
80 //-----------------------------------------------------------------------------
81 // rules to parse CFG file.
82 namespace CFG
83 {
84 using namespace Common;
85 
86 // Rule that matches a Comment. Consume everything on the line following a ';'
87 struct Comment : seq<string<';'>, until<eolf>> {};
88 
89 struct WS_Required : sor<Comment, eol, plus<space>> {};
90 struct WS : star<WS_Required> {};
91 
92 struct Value : plus<not_one<';', '}', '\r', '\n'>> {};
93 
94 struct ParameterName : identifier {};
95 struct Statement : seq<ParameterName, WS_Required, Value> {};
96 struct StatementOther : seq<ParameterName, WS_Required, plus<not_one<'}','{',';'>>> {};
97 
98 struct Motion : seq<TAO_PEGTL_STRING("motion"), WS, one<'{'>, WS, list<Statement, WS>, WS, one<'}'>> {};
99 struct Motions : seq<TAO_PEGTL_STRING("motions"), WS, one<'{'>, WS, list<Motion, WS>, WS, one<'}'>> {};
100 
101 struct OtherNonNested : seq<identifier, WS, one<'{'>, WS, list<StatementOther, WS>, WS, one<'}'>> {};
102 
103 struct OtherNested : seq<identifier, WS, one<'{'>, WS,
104  list<sor<OtherNonNested, StatementOther>, WS>,
105  WS, one<'}'>> {};
106 
107 struct Lines : sor<Comment, space, Motions, OtherNonNested, OtherNested> {};
108 
109 struct Grammar : star<Lines> {};
110 
111 } // namespace CFG
112 
113 } // namespace MotionFX
114 
115 #endif
116 // VTK-HeaderTest-Exclude: vtkMotionFXCFGGrammar.h