Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
RigDef_Regexes.h
Go to the documentation of this file.
1/*
2 This source file is part of Rigs of Rods
3 Copyright 2005-2012 Pierre-Michel Ricordel
4 Copyright 2007-2012 Thomas Fischer
5 Copyright 2013-2020 Petr Ohlidal
6
7 For more information, see http://www.rigsofrods.org/
8
9 Rigs of Rods is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License version 3, as
11 published by the Free Software Foundation.
12
13 Rigs of Rods is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20*/
21
51#pragma once
52
53#include <regex>
54
55namespace RigDef
56{
57
58namespace Regexes
59{
60
61// -------------------------------------------------------------------------- //
62// Repeatedly used bits of regular expressions //
63// Using #define-s instead of const vars to utilize C-string concatenation //
64// REMEMBER! Do not use captures () - they would mess up result order. Use | //
65// REMEMBER! Expressions using | MUST be enclosed in E_CAPTURE() //
66// -------------------------------------------------------------------------- //
67
68#define E_SLASH "\\/"
69
70#define E_OPTIONAL_SPACE "[[:blank:]]*"
71
72#define E_OR "|"
73
74#define E_TRAILING_WHITESPACE "[[:blank:]]*$"
75
76#define E_LEADING_WHITESPACE "^[[:blank:]]*"
77
78#define E_DELIMITER_SPACE "[[:blank:]]+"
79
80#define E_DELIMITER_CLASSIC "[[:blank:],:|]+" // Separators: space/comma/colon/pipe, see also `IsSeparator()` in RigDef_Parser.cpp. This is what original parser did.
81
82#define E_NODE_ID "[[:alnum:]_-]+"
83
84// --------------------------------------------------------------------------
85// Macros
86// --------------------------------------------------------------------------
87
89#define E_CAPTURE(_REGEXP_) \
90 "(" _REGEXP_ ")"
91
93#define E_CAPTURE_OPTIONAL(_REGEXP_) \
94 "(" _REGEXP_ ")?"
95
97#define E_KEYWORD_BLOCK(_NAME_) \
98 "(^" _NAME_ "[[:blank:]]*$)?"
99
101#define E_KEYWORD_INLINE(_NAME_) \
102 "(^" _NAME_ E_DELIMITER_CLASSIC ".*$)?"
103
105#define E_KEYWORD_INLINE_UNSEPARATED(_NAME_) \
106 "(^" _NAME_ ".*$)?"
107
109#define DEFINE_REGEX(_NAME_,_REGEXP_) \
110 const std::regex _NAME_ = std::regex( _REGEXP_, std::regex::ECMAScript);
111
112#define DEFINE_REGEX_IGNORECASE(_NAME_,_REGEXP_) \
113 const std::regex _NAME_ = std::regex( _REGEXP_, std::regex::ECMAScript | std::regex::icase);
114
115// -------------------------------------------------------------------------- //
116// Utility regexes //
117// -------------------------------------------------------------------------- //
118
119// IMPORTANT! If you add a value here, you must also modify File::Keywords enum, it relies on positions in this regex
120#define IDENTIFY_KEYWORD_REGEX_STRING \
121 E_KEYWORD_INLINE("add_animation") /* Position 1 */ \
122 E_KEYWORD_BLOCK("airbrakes") /* Position 2 */ \
123 E_KEYWORD_BLOCK("animators") /* Position 3 etc... */ \
124 E_KEYWORD_INLINE("AntiLockBrakes") \
125 E_KEYWORD_BLOCK("assetpacks") \
126 E_KEYWORD_INLINE("author") \
127 E_KEYWORD_BLOCK("axles") \
128 E_KEYWORD_BLOCK("backmesh") \
129 E_KEYWORD_BLOCK("beams") \
130 E_KEYWORD_BLOCK("brakes") \
131 E_KEYWORD_BLOCK("cab") \
132 E_KEYWORD_BLOCK("camerarail") \
133 E_KEYWORD_BLOCK("cameras") \
134 E_KEYWORD_BLOCK("cinecam") \
135 E_KEYWORD_BLOCK("collisionboxes") \
136 E_KEYWORD_BLOCK("commands") \
137 E_KEYWORD_BLOCK("commands2") \
138 E_KEYWORD_BLOCK("comment") \
139 E_KEYWORD_BLOCK("contacters") \
140 E_KEYWORD_INLINE("cruisecontrol") \
141 E_KEYWORD_BLOCK("customdashboardinputs") \
142 E_KEYWORD_INLINE("default_skin") \
143 E_KEYWORD_BLOCK("description") \
144 E_KEYWORD_INLINE("detacher_group") \
145 E_KEYWORD_BLOCK("disabledefaultsounds") \
146 E_KEYWORD_BLOCK("enable_advanced_deformation") \
147 E_KEYWORD_BLOCK("end") \
148 E_KEYWORD_BLOCK("end_comment") \
149 E_KEYWORD_BLOCK("end_description") \
150 E_KEYWORD_BLOCK("end_section") \
151 E_KEYWORD_BLOCK("engine") \
152 E_KEYWORD_BLOCK("engoption") \
153 E_KEYWORD_BLOCK("engturbo") \
154 E_KEYWORD_BLOCK("envmap") \
155 E_KEYWORD_BLOCK("exhausts") \
156 E_KEYWORD_INLINE("extcamera") \
157 E_KEYWORD_INLINE("fileformatversion") \
158 E_KEYWORD_INLINE("fileinfo") \
159 E_KEYWORD_BLOCK("fixes") \
160 E_KEYWORD_BLOCK("flares") \
161 E_KEYWORD_BLOCK("flares2") \
162 E_KEYWORD_BLOCK("flares3") \
163 E_KEYWORD_BLOCK("flaregroups_no_import") \
164 E_KEYWORD_BLOCK("flexbodies") \
165 E_KEYWORD_INLINE("flexbody_camera_mode") \
166 E_KEYWORD_BLOCK("flexbodywheels") \
167 E_KEYWORD_INLINE_UNSEPARATED("forset") \
168 E_KEYWORD_INLINE("forvert") \
169 E_KEYWORD_BLOCK("forwardcommands") \
170 E_KEYWORD_BLOCK("fusedrag") \
171 E_KEYWORD_BLOCK("globals") \
172 E_KEYWORD_INLINE("guid") \
173 E_KEYWORD_BLOCK("guisettings") \
174 E_KEYWORD_BLOCK("help") \
175 E_KEYWORD_BLOCK("hideInChooser") \
176 E_KEYWORD_BLOCK("hookgroup") \
177 E_KEYWORD_BLOCK("hooks") \
178 E_KEYWORD_BLOCK("hydros") \
179 E_KEYWORD_BLOCK("importcommands") \
180 E_KEYWORD_BLOCK("interaxles") \
181 E_KEYWORD_BLOCK("lockgroups") \
182 E_KEYWORD_BLOCK("lockgroup_default_nolock") \
183 E_KEYWORD_BLOCK("managedmaterials") \
184 E_KEYWORD_BLOCK("materialflarebindings") \
185 E_KEYWORD_BLOCK("meshwheels") \
186 E_KEYWORD_BLOCK("meshwheels2") \
187 E_KEYWORD_BLOCK("minimass") \
188 E_KEYWORD_BLOCK("nodecollision") \
189 E_KEYWORD_BLOCK("nodes") \
190 E_KEYWORD_BLOCK("nodes2") \
191 E_KEYWORD_BLOCK("particles") \
192 E_KEYWORD_BLOCK("pistonprops") \
193 E_KEYWORD_INLINE("prop_camera_mode") \
194 E_KEYWORD_BLOCK("props") \
195 E_KEYWORD_BLOCK("railgroups") \
196 E_KEYWORD_BLOCK("rescuer") \
197 E_KEYWORD_BLOCK("rigidifiers") \
198 E_KEYWORD_BLOCK("rollon") \
199 E_KEYWORD_BLOCK("ropables") \
200 E_KEYWORD_BLOCK("ropes") \
201 E_KEYWORD_BLOCK("rotators") \
202 E_KEYWORD_BLOCK("rotators2") \
203 E_KEYWORD_BLOCK("screwprops") \
204 E_KEYWORD_BLOCK("scripts") \
205 E_KEYWORD_INLINE("section") \
206 E_KEYWORD_INLINE("sectionconfig") \
207 E_KEYWORD_INLINE("set_beam_defaults") \
208 E_KEYWORD_INLINE("set_beam_defaults_scale") \
209 E_KEYWORD_INLINE("set_collision_range") \
210 E_KEYWORD_INLINE("set_default_minimass") \
211 E_KEYWORD_INLINE("set_inertia_defaults") \
212 E_KEYWORD_INLINE("set_managedmaterials_options") \
213 E_KEYWORD_INLINE("set_node_defaults") \
214 E_KEYWORD_BLOCK("set_shadows") \
215 E_KEYWORD_INLINE("set_skeleton_settings") \
216 E_KEYWORD_BLOCK("shocks") \
217 E_KEYWORD_BLOCK("shocks2") \
218 E_KEYWORD_BLOCK("shocks3") \
219 E_KEYWORD_BLOCK("slidenode_connect_instantly") \
220 E_KEYWORD_BLOCK("slidenodes") \
221 E_KEYWORD_INLINE("SlopeBrake") \
222 E_KEYWORD_BLOCK("soundsources") \
223 E_KEYWORD_BLOCK("soundsources2") \
224 E_KEYWORD_INLINE("speedlimiter") \
225 E_KEYWORD_BLOCK("submesh") \
226 E_KEYWORD_INLINE("submesh_groundmodel") \
227 E_KEYWORD_BLOCK("texcoords") \
228 E_KEYWORD_BLOCK("ties") \
229 E_KEYWORD_BLOCK("torquecurve") \
230 E_KEYWORD_INLINE("TractionControl") \
231 E_KEYWORD_BLOCK("transfercase") \
232 E_KEYWORD_BLOCK("triggers") \
233 E_KEYWORD_BLOCK("turbojets") \
234 E_KEYWORD_BLOCK("turboprops") \
235 E_KEYWORD_BLOCK("turboprops2") \
236 E_KEYWORD_BLOCK("videocamera") \
237 E_KEYWORD_BLOCK("wheeldetachers") \
238 E_KEYWORD_BLOCK("wheels") \
239 E_KEYWORD_BLOCK("wheels2") \
240 E_KEYWORD_BLOCK("wings")
241
242DEFINE_REGEX_IGNORECASE( IDENTIFY_KEYWORD_IGNORE_CASE, IDENTIFY_KEYWORD_REGEX_STRING )
243
244#define E_2xCAPTURE_TRAILING_COMMENT \
245 E_OPTIONAL_SPACE \
246 E_CAPTURE_OPTIONAL( \
247 E_CAPTURE( \
248 ";" \
249 E_OR \
250 E_SLASH E_SLASH \
251 ) \
252 ".*" \
253 ) \
254 "$"
255
256// -------------------------------------------------------------------------- //
257// Regexes for parsing sections //
258// -------------------------------------------------------------------------- //
259
260DEFINE_REGEX( PARSE_ANIMATORS_NUMBERED_KEYWORD,
262 E_CAPTURE( "throttle|rpm|aerotorq|aeropit|aerostatus" )
263 E_CAPTURE( "[[:digit:]]" )
265 );
266
267DEFINE_REGEX( SECTION_AXLES_PROPERTY,
269 E_CAPTURE_OPTIONAL( // #1
271 "w(1|2)" // #2 wheel number
272 "\\("
273 E_CAPTURE( E_NODE_ID ) // #3 Node 1
275 E_CAPTURE( E_NODE_ID ) // #4 Node 2
276 "\\)"
278 )
279 E_CAPTURE_OPTIONAL( // #5
281 "d\\("
282 E_CAPTURE( "[olsv]*" ) // #6 Differential modes
283 "\\)"
285 )
287 );
288
289
290
291// -------------------------------------------------------------------------- //
292// Cleanup //
293// -------------------------------------------------------------------------- //
294
295
296#undef E_SLASH
297#undef E_TRAILING_WHITESPACE
298#undef E_LEADING_WHITESPACE
299#undef E_DELIMITER_SPACE
300#undef E_OPTIONAL_SPACE
301#undef E_OR
302#undef E_NODE_ID
303#undef E_CAPTURE
304#undef E_CAPTURE_OPTIONAL
305#undef DEFINE_REGEX
306#undef E_2xCAPTURE_TRAILING_COMMENT
307
308} // namespace Regexes
309
310} // namespace RigDef
#define IDENTIFY_KEYWORD_REGEX_STRING
#define E_OPTIONAL_SPACE
#define E_CAPTURE_OPTIONAL(_REGEXP_)
Encloses expression in 'capture' marks with ? (zero or one time) mark.
#define E_2xCAPTURE_TRAILING_COMMENT
#define E_LEADING_WHITESPACE
#define E_CAPTURE(_REGEXP_)
Encloses expression in 'capture' marks.
#define E_DELIMITER_SPACE
#define E_NODE_ID
#define E_TRAILING_WHITESPACE
#define DEFINE_REGEX(_NAME_, _REGEXP_)
Actual regex definition macro.
#define DEFINE_REGEX_IGNORECASE(_NAME_, _REGEXP_)