2
// Copyright 1997 - 2001, Paul C. Gregory
4
// Contact: pgregory@aqsis.org
6
// This library is free software; you can redistribute it and/or
7
// modify it under the terms of the GNU Lesser General Public
8
// License as published by the Free Software Foundation; either
9
// version 2.1 of the License, or (at your option) any later version.
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
// General Public License for more details.
16
// You should have received a copy of the GNU General Public
17
// License along with this library; if not, write to the Free Software
18
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
* \brief A class to parse RiDeclare and inline parameter list definitions.
22
* \author Lionel J. Lacour (intuition01@online.fr)
24
#include "inlineparse.h"
26
USING_NAMESPACE( libri2rib );
28
void CqInlineParse::check_syntax ()
30
// number_of_words =0 ---> ERROR
31
// number_of_words =1 ---> not an inline def
32
// number_of_words =2 ---> type id
33
// number_of_words =3 ---> class type id
34
// number_of_words =4 ---> ERROR
35
// number_of_words =5 ---> type [ size ] id
36
// number_of_words =6 ---> class type [ size ] id
37
// number_of_words =7 ---> ERROR
39
switch ( number_of_words )
42
throw CqError ( RIE_SYNTAX, RIE_ERROR, "void parameter declaration", TqFalse );
45
throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
52
if ( is_type( word[ 0 ] ) == TqFalse )
54
throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
58
tt = get_type( word[ 0 ] );
60
identifier = word[ 1 ];
65
if ( ( is_class( word[ 0 ] ) == TqFalse ) || ( is_type( word[ 1 ] ) == TqFalse ) )
67
throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
70
tc = get_class( word[ 0 ] );
71
tt = get_type( word[ 1 ] );
73
identifier = word[ 2 ];
77
if ( ( is_type( word[ 0 ] ) == TqFalse ) || ( word[ 1 ] != "[" ) ||
78
( is_int( word[ 2 ] ) == TqFalse ) || ( word[ 3 ] != "]" ) )
80
throw CqError ( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
84
tt = get_type( word[ 0 ] );
85
size = get_size( word[ 2 ] );
86
identifier = word[ 4 ];
91
if ( ( is_class( word[ 0 ] ) == TqFalse ) || ( is_type( word[ 1 ] ) == TqFalse ) ||
92
( word[ 2 ] != "[" ) || ( is_int( word[ 3 ] ) == TqFalse ) ||
93
( word[ 4 ] != "]" ) )
95
throw CqError( RIE_SYNTAX, RIE_ERROR, "Bad inline declaration", TqTrue );
98
tc = get_class( word[ 0 ] );
99
tt = get_type( word[ 1 ] );
100
size = get_size( word[ 3 ] );
101
identifier = word[ 5 ];
106
void CqInlineParse::parse ( std::string &str )
116
start_found = TqFalse;
118
for ( i = 0;( i < str.length() ) && ( j < 7 );i++ )
125
if ( start_found == TqTrue )
127
word[ j ] = str.substr( sp, sz );
131
start_found = TqFalse;
134
throw CqError( RIE_SYNTAX, RIE_ERROR, "'#' character not allowed in strings", TqTrue );
136
throw CqError( RIE_SYNTAX, RIE_ERROR, "'\"' character not allowed in strings", TqTrue );
139
if ( start_found == TqTrue )
141
word[ j ] = str.substr( sp, sz );
143
start_found = TqFalse;
147
word[ j ] = str.substr( sp, sz );
151
if ( start_found == TqTrue )
156
start_found = TqTrue;
161
// if there is no space at the end of the string,
162
// the previous loop will not notice the end of the word,
163
// and so will 'forget' to store it.
164
if ( start_found == TqTrue )
166
word[ j ] = str.substr( sp, sz );
173
TqBool CqInlineParse::is_class ( const std::string &str )
175
if ( ( str == "constant" ) ||
176
( str == "uniform" ) ||
177
( str == "varying" ) ||
178
( str == "vertex" ) ||
179
( str == "facevarying") )
184
TqBool CqInlineParse::is_type ( const std::string &str )
186
if ( ( str == "float" ) ||
187
( str == "point" ) ||
188
( str == "vector" ) ||
189
( str == "normal" ) ||
190
( str == "color" ) ||
191
( str == "string" ) ||
192
( str == "matrix" ) ||
193
( str == "hpoint" ) ||
194
( str == "integer" ) ||
200
// check if this int is >0 too
201
TqBool CqInlineParse::is_int ( const std::string &str )
204
i = sscanf( str.c_str(), "%d", &j );
205
if ( ( i != 1 ) || ( j <= 0 ) )
210
EqTokenClass CqInlineParse::get_class ( const std::string &str )
212
if ( str == "constant" )
214
if ( str == "uniform" )
216
if ( str == "varying" )
218
if ( str == "vertex" )
220
if ( str == "facevarying" )
225
EqTokenType CqInlineParse::get_type ( const std::string &str )
227
if ( str == "float" )
229
if ( str == "point" )
231
if ( str == "vector" )
233
if ( str == "normal" )
235
if ( str == "color" )
237
if ( str == "string" )
239
if ( str == "matrix" )
241
if ( str == "hpoint" )
243
if ( str == "integer" )
250
TqUint CqInlineParse::get_size ( const std::string &str )
253
sscanf( str.c_str(), "%u", &i );
257
void CqInlineParse::lc( std::string &str )
259
for ( TqUint i = 0;i < str.length();i++ )
261
str[ i ] = tolower( str[ i ] );