~ubuntu-branches/ubuntu/trusty/codeblocks/trusty-proposed

« back to all changes in this revision

Viewing changes to src/sdk/scripting/squirrel/sqlexer.cpp

  • Committer: Bazaar Package Importer
  • Author(s): David Paleino
  • Date: 2011-01-22 20:58:57 UTC
  • mfrom: (3.1.3 maverick)
  • Revision ID: james.westby@ubuntu.com-20110122205857-mlwokxogiic0dnu7
Tags: 10.05-1
* Initial Debian release (Closes: #304570)
* Setting myself as Maintainer, original Ubuntu maintainer set as
  Uploader
* Use debian/watch to get the original tarball, instead of an ad-hoc
  script
* Wrap multivalue fields in debian/control
* Update debian/copyright with lots of missing info, and use DEP-5
* Add missing linkage to libX11 (03-fix_libX11_linkage.patch)
* Use dh7 for debian/rules
* Build-Depend on dh-autoreconf, since we need to re-generate autotools
  machinery (libtool version mismatch)
* Migrate from libwxsmithlib0-dev to libwxsmithlib-dev, to ease
  future SONAME bumps.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
        ADD_KEYWORD(true,TK_TRUE);
67
67
        ADD_KEYWORD(false,TK_FALSE);
68
68
        ADD_KEYWORD(static,TK_STATIC);
 
69
        ADD_KEYWORD(enum,TK_ENUM);
 
70
        ADD_KEYWORD(const,TK_CONST);
69
71
 
70
72
        _readf = rg;
71
73
        _up = up;
135
137
                        case _SC('*'):
136
138
                                NEXT();
137
139
                                LexBlockComment();
138
 
                                continue;       
 
140
                                continue;
139
141
                        case _SC('/'):
140
142
                                do { NEXT(); } while (CUR_CHAR != _SC('\n') && (!IS_EOB()));
141
143
                                continue;
165
167
                case _SC('>'):
166
168
                        NEXT();
167
169
                        if (CUR_CHAR == _SC('=')){ NEXT(); RETURN_TOKEN(TK_GE);}
168
 
                        else if(CUR_CHAR == _SC('>')){ 
169
 
                                NEXT(); 
 
170
                        else if(CUR_CHAR == _SC('>')){
 
171
                                NEXT();
170
172
                                if(CUR_CHAR == _SC('>')){
171
173
                                        NEXT();
172
174
                                        RETURN_TOKEN(TK_USHIFTR);
180
182
                        else { NEXT(); RETURN_TOKEN(TK_NE); }
181
183
                case _SC('@'): {
182
184
                        SQInteger stype;
183
 
                        NEXT(); 
 
185
                        NEXT();
184
186
                        if(CUR_CHAR != _SC('"'))
185
187
                                Error(_SC("string expected"));
186
188
                        if((stype=ReadString('"',true))!=-1) {
252
254
                                        SQInteger c = CUR_CHAR;
253
255
                                        if (sciscntrl((int)c)) Error(_SC("unexpected character(control)"));
254
256
                                        NEXT();
255
 
                                        RETURN_TOKEN(c);  
 
257
                                        RETURN_TOKEN(c);
256
258
                                }
257
259
                                RETURN_TOKEN(0);
258
260
                        }
259
261
                }
260
262
        }
261
 
        return 0;    
 
263
        return 0;
262
264
}
263
 
        
 
265
 
264
266
SQInteger SQLexer::GetIDType(SQChar *s)
265
267
{
266
268
        SQObjectPtr t;
282
284
                        case SQUIRREL_EOB:
283
285
                                Error(_SC("unfinished string"));
284
286
                                return -1;
285
 
                        case _SC('\n'): 
286
 
                                if(!verbatim) Error(_SC("newline in a constant")); 
287
 
                                APPEND_CHAR(CUR_CHAR); NEXT(); 
 
287
                        case _SC('\n'):
 
288
                                if(!verbatim) Error(_SC("newline in a constant"));
 
289
                                APPEND_CHAR(CUR_CHAR); NEXT();
288
290
                                _currentline++;
289
291
                                break;
290
292
                        case _SC('\\'):
291
293
                                if(verbatim) {
292
 
                                        APPEND_CHAR('\\'); NEXT(); 
 
294
                                        APPEND_CHAR('\\'); NEXT();
293
295
                                }
294
296
                                else {
295
297
                                        NEXT();
296
298
                                        switch(CUR_CHAR) {
297
299
                                        case _SC('x'): NEXT(); {
298
 
                                                if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected")); 
 
300
                                                if(!isxdigit(CUR_CHAR)) Error(_SC("hexadecimal number expected"));
299
301
                                                const SQInteger maxdigits = 4;
300
302
                                                SQChar temp[maxdigits+1];
301
303
                                                SQInteger n = 0;
372
374
        }
373
375
}
374
376
 
 
377
SQInteger scisodigit(SQInteger c) { return c >= _SC('0') && c <= _SC('7'); }
 
378
 
 
379
void LexOctal(const SQChar *s,SQUnsignedInteger *res)
 
380
{
 
381
        *res = 0;
 
382
        while(*s != 0)
 
383
        {
 
384
                if(scisodigit(*s)) *res = (*res)*8+((*s++)-'0');
 
385
                else { assert(0); }
 
386
        }
 
387
}
 
388
 
375
389
SQInteger isexponent(SQInteger c) { return c == 'e' || c=='E'; }
 
390
 
 
391
 
376
392
#define MAX_HEX_DIGITS (sizeof(SQInteger)*2)
377
393
SQInteger SQLexer::ReadNumber()
378
394
{
380
396
#define TFLOAT 2
381
397
#define THEX 3
382
398
#define TSCIENTIFIC 4
 
399
#define TOCTAL 5
383
400
        SQInteger type = TINT, firstchar = CUR_CHAR;
384
401
        SQChar *sTemp;
385
402
        INIT_TEMP_STRING();
386
403
        NEXT();
387
 
        if(firstchar == _SC('0') && toupper(CUR_CHAR) == _SC('X')) {
388
 
                NEXT();
389
 
                type = THEX;
390
 
                while(isxdigit(CUR_CHAR)) {
391
 
                        APPEND_CHAR(CUR_CHAR);
 
404
        if(firstchar == _SC('0') && (toupper(CUR_CHAR) == _SC('X') || scisodigit(CUR_CHAR)) ) {
 
405
                if(scisodigit(CUR_CHAR)) {
 
406
                        type = TOCTAL;
 
407
                        while(scisodigit(CUR_CHAR)) {
 
408
                                APPEND_CHAR(CUR_CHAR);
 
409
                                NEXT();
 
410
                        }
 
411
                        if(scisdigit(CUR_CHAR)) Error(_SC("invalid octal number"));
 
412
                }
 
413
                else {
392
414
                        NEXT();
 
415
                        type = THEX;
 
416
                        while(isxdigit(CUR_CHAR)) {
 
417
                                APPEND_CHAR(CUR_CHAR);
 
418
                                NEXT();
 
419
                        }
 
420
                        if(_longstr.size() > MAX_HEX_DIGITS) Error(_SC("too many digits for an Hex number"));
393
421
                }
394
 
                if(_longstr.size() > MAX_HEX_DIGITS) Error(_SC("too many digits for an Hex number"));
395
422
        }
396
423
        else {
397
 
                APPEND_CHAR((int)firstchar);
 
424
                // C::B patch: Eliminate compiler warnings
 
425
                APPEND_CHAR((char)firstchar);
398
426
                while (CUR_CHAR == _SC('.') || scisdigit(CUR_CHAR) || isexponent(CUR_CHAR)) {
399
427
            if(CUR_CHAR == _SC('.')) type = TFLOAT;
400
428
                        if(isexponent(CUR_CHAR)) {
408
436
                                }
409
437
                                if(!scisdigit(CUR_CHAR)) Error(_SC("exponent expected"));
410
438
                        }
411
 
                        
 
439
 
412
440
                        APPEND_CHAR(CUR_CHAR);
413
441
                        NEXT();
414
442
                }
425
453
        case THEX:
426
454
                LexHexadecimal(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
427
455
                return TK_INTEGER;
 
456
        case TOCTAL:
 
457
                LexOctal(&_longstr[0],(SQUnsignedInteger *)&_nvalue);
 
458
                return TK_INTEGER;
428
459
        }
429
460
        return 0;
430
461
}