~ubuntu-branches/ubuntu/raring/codeblocks/raring-proposed

« back to all changes in this revision

Viewing changes to src/sdk/wxscintilla/src/scintilla/src/LexRuby.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Cosme Domínguez Díaz
  • Date: 2010-08-09 04:38:38 UTC
  • mfrom: (1.1.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20100809043838-a59ygguym4eg0jgw
Tags: 10.05-0ubuntu1
* New upstream release. Closes (LP: #322350)
 - Switch to dpkg-source 3.0 (quilt) format
 - Remove unneeded README.source
 - Add debian/get-source-orig script that removes all
   Windows prebuilt binaries
* Bump Standards-Version to 3.9.1
 - Stop shipping *.la files
* debian/control
 - Add cdbs package as Build-Depend
 - Add libbz2-dev and zlib1g-dev packages as
   Build-Depends (needed by libhelp_plugin.so)
 - Remove dpatch package of Build-Depends
 - Add codeblocks-contrib-debug package
 - Split architecture-independent files of codeblocks
   package in codeblocks-common package
* debian/rules
 - Switch to CDBS rules system
 - Add parallel build support
 - Add a call to debian/get-source-orig script
 - Use lzma compression (saves 23,5 MB of free space)
* debian/patches
 - Refresh 01_codeblocks_plugin_path
 - Add 02_no_Makefiles_in_debian_dir to remove any link
   in codeblocks build system to deleted Makefiles of debian directory
 - Drop 02_ftbfs_gcc44 and 03_ftbfs_glib221 (merged in upstream)
* debian/watch
 - Update to use the new host (berlios.de)

Show diffs side-by-side

added added

removed removed

Lines of Context:
49
49
}
50
50
 
51
51
static inline bool isSafeWordcharOrHigh(char ch) {
52
 
    return isHighBitChar(ch) || iswordchar(ch);
 
52
    // Error: scintilla's KeyWords.h includes '.' as a word-char
 
53
    // we want to separate things that can take methods from the
 
54
    // methods.
 
55
    return isHighBitChar(ch) || isalnum(ch) || ch == '_';
53
56
}
54
57
 
55
58
static bool inline iswhitespace(char ch) {
95
98
                              Accessor &styler);
96
99
 
97
100
static int ClassifyWordRb(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler, char *prevWord) {
98
 
        char s[100];
 
101
        char s[MAX_KEYWORD_LENGTH];
99
102
    unsigned int i, j;
100
103
        unsigned int lim = end - start + 1; // num chars to copy
101
104
        if (lim >= MAX_KEYWORD_LENGTH) {
238
241
    return true;
239
242
}
240
243
 
 
244
// This class is used by the enter and exit methods, so it needs
 
245
// to be hoisted out of the function.
 
246
 
 
247
class QuoteCls {
 
248
    public:
 
249
    int  Count;
 
250
    char Up;
 
251
    char Down;
 
252
    QuoteCls() {
 
253
        this->New();
 
254
    }
 
255
    void New() {
 
256
        Count = 0;
 
257
        Up    = '\0';
 
258
        Down  = '\0';
 
259
    }
 
260
    void Open(char u) {
 
261
        Count++;
 
262
        Up    = u;
 
263
        Down  = opposite(Up);
 
264
    }
 
265
    QuoteCls(const QuoteCls& q) {
 
266
        // copy constructor -- use this for copying in
 
267
        Count = q.Count;
 
268
        Up    = q.Up;
 
269
        Down  = q.Down;
 
270
    }
 
271
    QuoteCls& operator=(const QuoteCls& q) { // assignment constructor
 
272
        if (this != &q) {
 
273
            Count = q.Count;
 
274
            Up    = q.Up;
 
275
            Down  = q.Down;
 
276
        }
 
277
                return *this;
 
278
    }
 
279
            
 
280
};
 
281
 
 
282
 
 
283
static void enterInnerExpression(int  *p_inner_string_types,
 
284
                                 int  *p_inner_expn_brace_counts,
 
285
                                 QuoteCls *p_inner_quotes,
 
286
                                 int&  inner_string_count,
 
287
                                 int&  state,
 
288
                                 int&  brace_counts,
 
289
                                 QuoteCls curr_quote
 
290
                                 ) {
 
291
    p_inner_string_types[inner_string_count] = state;
 
292
    state = SCE_RB_DEFAULT;
 
293
    p_inner_expn_brace_counts[inner_string_count] = brace_counts;
 
294
    brace_counts = 0;
 
295
    p_inner_quotes[inner_string_count] = curr_quote;
 
296
    ++inner_string_count;
 
297
}
 
298
 
 
299
static void exitInnerExpression(int *p_inner_string_types,
 
300
                                 int *p_inner_expn_brace_counts,
 
301
                                 QuoteCls *p_inner_quotes,
 
302
                                 int& inner_string_count,
 
303
                                 int& state,
 
304
                                 int&  brace_counts,
 
305
                                 QuoteCls& curr_quote
 
306
                                ) {
 
307
    --inner_string_count;
 
308
    state = p_inner_string_types[inner_string_count];
 
309
    brace_counts = p_inner_expn_brace_counts[inner_string_count];
 
310
    curr_quote = p_inner_quotes[inner_string_count];
 
311
}
241
312
 
242
313
static bool isEmptyLine(int pos,
243
314
                        Accessor &styler) {
288
359
//
289
360
// iPrev points to the start of <<
290
361
 
291
 
static bool sureThisIsHeredoc(int iPrev, 
 
362
static bool sureThisIsHeredoc(int iPrev,
292
363
                              Accessor &styler,
293
364
                              char *prevWord) {
294
365
                    
605
676
        };
606
677
        HereDocCls HereDoc;     
607
678
 
608
 
        class QuoteCls {
609
 
                public:
610
 
                int  Count;
611
 
                char Up;
612
 
                char Down;
613
 
                QuoteCls() {
614
 
                        this->New();
615
 
                }
616
 
                void New() {
617
 
                        Count = 0;
618
 
                        Up    = '\0';
619
 
                        Down  = '\0';
620
 
                }
621
 
                void Open(char u) {
622
 
                        Count++;
623
 
                        Up    = u;
624
 
                        Down  = opposite(Up);
625
 
                }
626
 
        };
627
679
        QuoteCls Quote;
628
680
 
629
681
    int numDots = 0;  // For numbers --
643
695
 
644
696
        char chPrev = styler.SafeGetCharAt(startPos - 1);
645
697
        char chNext = styler.SafeGetCharAt(startPos);
 
698
        bool is_real_number = true;   // Differentiate between constants and ?-sequences.
646
699
        // Ruby uses a different mask because bad indentation is marked by oring with 32
647
700
        styler.StartAt(startPos, 127);
648
701
        styler.StartSegment(startPos);
654
707
                             SCE_RB_STRING_QW,
655
708
                             SCE_RB_STRING_QX};
656
709
    static const char* q_chars = "qQrwWx";
657
 
    
658
 
        for (int i = startPos; i < lengthDoc; i++) {
 
710
 
 
711
    // In most cases a value of 2 should be ample for the code in the
 
712
    // Ruby library, and the code the user is likely to enter.
 
713
    // For example,
 
714
    // fu_output_message "mkdir #{options[:mode] ? ('-m %03o ' % options[:mode]) : ''}#{list.join ' '}"
 
715
    //     if options[:verbose]
 
716
    // from fileutils.rb nests to a level of 2
 
717
    // If the user actually hits a 6th occurrence of '#{' in a double-quoted
 
718
    // string (including regex'es, %Q, %<sym>, %w, and other strings
 
719
    // that interpolate), it will stay as a string.  The problem with this
 
720
    // is that quotes might flip, a 7th '#{' will look like a comment,
 
721
    // and code-folding might be wrong.
 
722
 
 
723
    // If anyone runs into this problem, I recommend raising this
 
724
    // value slightly higher to replacing the fixed array with a linked
 
725
    // list.  Keep in mind this code will be called everytime the lexer
 
726
    // is invoked.
 
727
 
 
728
#define INNER_STRINGS_MAX_COUNT 5
 
729
    // These vars track our instances of "...#{,,,%Q<..#{,,,}...>,,,}..."
 
730
    int inner_string_types[INNER_STRINGS_MAX_COUNT];
 
731
    // Track # braces when we push a new #{ thing
 
732
    int inner_expn_brace_counts[INNER_STRINGS_MAX_COUNT];
 
733
    QuoteCls inner_quotes[INNER_STRINGS_MAX_COUNT];
 
734
    int inner_string_count = 0;
 
735
    int brace_counts = 0;   // Number of #{ ... } things within an expression
 
736
 
 
737
    int i;
 
738
        for (i = 0; i < INNER_STRINGS_MAX_COUNT; i++) {
 
739
        inner_string_types[i] = 0;
 
740
        inner_expn_brace_counts[i] = 0;
 
741
    }
 
742
        for (i = startPos; i < lengthDoc; i++) {
659
743
                char ch = chNext;
660
744
                chNext = styler.SafeGetCharAt(i + 1);
661
745
                char chNext2 = styler.SafeGetCharAt(i + 2);
690
774
            if (isSafeDigit(ch)) {
691
775
                styler.ColourTo(i - 1, state);
692
776
                                state = SCE_RB_NUMBER;
 
777
                is_real_number = true;
693
778
                numDots = 0;
694
779
            } else if (isHighBitChar(ch) || iswordstart(ch)) {
695
780
                styler.ColourTo(i - 1, state);
699
784
                                state = SCE_RB_COMMENTLINE;
700
785
                        } else if (ch == '=') {
701
786
                                // =begin indicates the start of a comment (doc) block
702
 
                if (i == 0 || isEOLChar(chPrev)
 
787
                if (i == 0 || (isEOLChar(chPrev)
703
788
                    && chNext == 'b'
704
789
                    && styler.SafeGetCharAt(i + 2) == 'e'
705
790
                    && styler.SafeGetCharAt(i + 3) == 'g'
706
791
                    && styler.SafeGetCharAt(i + 4) == 'i'
707
792
                    && styler.SafeGetCharAt(i + 5) == 'n'
708
 
                    && !isSafeWordcharOrHigh(styler.SafeGetCharAt(i + 6))) {
 
793
                    && !isSafeWordcharOrHigh(styler.SafeGetCharAt(i + 6)))) {
709
794
                    styler.ColourTo(i - 1, state);
710
795
                    state = SCE_RB_POD;
711
796
                                } else {
885
970
                                                chNext = styler.SafeGetCharAt(i + 1);
886
971
                        have_string = true;
887
972
                    }
888
 
                } else if (!isSafeWordcharOrHigh(chNext)) {
 
973
                } else if (preferRE && !isSafeWordcharOrHigh(chNext)) {
889
974
                    // Ruby doesn't allow high bit chars here,
890
975
                    // but the editor host might
891
976
                    state = SCE_RB_STRING_QQ;
898
983
                    // stay in default
899
984
                    preferRE = true;
900
985
                }
 
986
            } else if (ch == '?') {
 
987
                styler.ColourTo(i - 1, state);
 
988
                if (iswhitespace(chNext) || chNext == '\n' || chNext == '\r') {
 
989
                    styler.ColourTo(i, SCE_RB_OPERATOR);
 
990
                } else {
 
991
                    // It's the start of a character code escape sequence
 
992
                    // Color it as a number.
 
993
                    state = SCE_RB_NUMBER;
 
994
                    is_real_number = false;
 
995
                }
901
996
            } else if (isoperator(ch) || ch == '.') {
902
997
                                styler.ColourTo(i - 1, state);
903
998
                                styler.ColourTo(i, SCE_RB_OPERATOR);
909
1004
                // we aren't ending an object exp'n, and ops
910
1005
                // like : << / are unary operators.
911
1006
                
912
 
                preferRE = (strchr(")}].", ch) == NULL);
 
1007
                if (ch == '{') {
 
1008
                    ++brace_counts;
 
1009
                    preferRE = true;
 
1010
                } else if (ch == '}' && --brace_counts < 0
 
1011
                           && inner_string_count > 0) {
 
1012
                    styler.ColourTo(i, SCE_RB_OPERATOR);
 
1013
                    exitInnerExpression(inner_string_types,
 
1014
                                        inner_expn_brace_counts,
 
1015
                                        inner_quotes,
 
1016
                                        inner_string_count,
 
1017
                                        state, brace_counts, Quote);
 
1018
                } else {
 
1019
                    preferRE = (strchr(")}].", ch) == NULL);
 
1020
                }
913
1021
                // Stay in default state
914
1022
            } else if (isEOLChar(ch)) {
915
1023
                // Make sure it's a true line-end, with no backslash
984
1092
                }
985
1093
            }
986
1094
        } else if (state == SCE_RB_NUMBER) {
987
 
            if (isSafeAlnumOrHigh(ch) || ch == '_') {
 
1095
            if (!is_real_number) {
 
1096
                if (ch != '\\') {
 
1097
                    styler.ColourTo(i, state);
 
1098
                    state = SCE_RB_DEFAULT;
 
1099
                    preferRE = false;
 
1100
                } else if (strchr("\\ntrfvaebs", chNext)) {
 
1101
                    // Terminal escape sequence -- handle it next time
 
1102
                    // Nothing more to do this time through the loop
 
1103
                } else if (chNext == 'C' || chNext == 'M') {
 
1104
                    if (chNext2 != '-') {
 
1105
                        // \C or \M ends the sequence -- handle it next time
 
1106
                    } else {
 
1107
                        // Move from abc?\C-x
 
1108
                        //               ^
 
1109
                        // to
 
1110
                        //                 ^
 
1111
                        i += 2;
 
1112
                        ch = chNext2;
 
1113
                        chNext = styler.SafeGetCharAt(i + 1);
 
1114
                    }
 
1115
                } else if (chNext == 'c') {
 
1116
                    // Stay here, \c is a combining sequence
 
1117
                    advance_char(i, ch, chNext, chNext2); // pass by ref
 
1118
                } else {
 
1119
                    // ?\x, including ?\\ is final.
 
1120
                    styler.ColourTo(i + 1, state);
 
1121
                    state = SCE_RB_DEFAULT;
 
1122
                    preferRE = false;
 
1123
                    advance_char(i, ch, chNext, chNext2);
 
1124
                }
 
1125
            } else if (isSafeAlnumOrHigh(ch) || ch == '_') {
988
1126
                // Keep going
989
1127
            } else if (ch == '.' && ++numDots == 1) {
990
1128
                // Keep going
1155
1293
                Quote.Count++;
1156
1294
                
1157
1295
            } else if (ch == '#' ) {
1158
 
                //todo: distinguish comments from pound chars
1159
 
                // for now, handle as comment
1160
 
                styler.ColourTo(i - 1, state);
1161
 
                bool inEscape = false;
1162
 
                while (++i < lengthDoc) {
1163
 
                    ch = styler.SafeGetCharAt(i);
1164
 
                    if (ch == '\\') {
1165
 
                        inEscape = true;
1166
 
                    } else if (isEOLChar(ch)) {
1167
 
                        // Comment inside a regex
1168
 
                        styler.ColourTo(i - 1, SCE_RB_COMMENTLINE);
1169
 
                        break;
1170
 
                    } else if (inEscape) {
1171
 
                        inEscape = false;  // don't look at char
1172
 
                    } else if (ch == Quote.Down) {
1173
 
                        // Have the regular handler deal with this
1174
 
                        // to get trailing modifiers.
1175
 
                        i--;
1176
 
                        ch = styler[i];
1177
 
                                                break;
 
1296
                if (chNext == '{'
 
1297
                    && inner_string_count < INNER_STRINGS_MAX_COUNT) {
 
1298
                    // process #{ ... }
 
1299
                    styler.ColourTo(i - 1, state);
 
1300
                    styler.ColourTo(i + 1, SCE_RB_OPERATOR);
 
1301
                    enterInnerExpression(inner_string_types,
 
1302
                                         inner_expn_brace_counts,
 
1303
                                         inner_quotes,
 
1304
                                         inner_string_count,
 
1305
                                         state,
 
1306
                                         brace_counts,
 
1307
                                         Quote);
 
1308
                    preferRE = true;
 
1309
                    // Skip one
 
1310
                    advance_char(i, ch, chNext, chNext2);
 
1311
                } else {
 
1312
                    //todo: distinguish comments from pound chars
 
1313
                    // for now, handle as comment
 
1314
                    styler.ColourTo(i - 1, state);
 
1315
                    bool inEscape = false;
 
1316
                    while (++i < lengthDoc) {
 
1317
                        ch = styler.SafeGetCharAt(i);
 
1318
                        if (ch == '\\') {
 
1319
                            inEscape = true;
 
1320
                        } else if (isEOLChar(ch)) {
 
1321
                            // Comment inside a regex
 
1322
                            styler.ColourTo(i - 1, SCE_RB_COMMENTLINE);
 
1323
                            break;
 
1324
                        } else if (inEscape) {
 
1325
                            inEscape = false;  // don't look at char
 
1326
                        } else if (ch == Quote.Down) {
 
1327
                            // Have the regular handler deal with this
 
1328
                            // to get trailing modifiers.
 
1329
                            i--;
 
1330
                            ch = styler[i];
 
1331
                            break;
 
1332
                        }
1178
1333
                    }
 
1334
                    chNext = styler.SafeGetCharAt(i + 1);
 
1335
                    chNext2 = styler.SafeGetCharAt(i + 2);
1179
1336
                }
1180
 
                chNext = styler.SafeGetCharAt(i + 1);
1181
 
                chNext2 = styler.SafeGetCharAt(i + 2);
1182
1337
            }
1183
1338
        // Quotes of all kinds...
1184
1339
        } else if (state == SCE_RB_STRING_Q || state == SCE_RB_STRING_QQ || 
1199
1354
                }
1200
1355
            } else if (ch == Quote.Up) {
1201
1356
                Quote.Count++;
 
1357
            } else if (ch == '#' && chNext == '{'
 
1358
                       && inner_string_count < INNER_STRINGS_MAX_COUNT
 
1359
                       && state != SCE_RB_CHARACTER
 
1360
                       && state != SCE_RB_STRING_Q) {
 
1361
                // process #{ ... }
 
1362
                styler.ColourTo(i - 1, state);
 
1363
                styler.ColourTo(i + 1, SCE_RB_OPERATOR);
 
1364
                enterInnerExpression(inner_string_types,
 
1365
                                     inner_expn_brace_counts,
 
1366
                                     inner_quotes,
 
1367
                                     inner_string_count,
 
1368
                                     state,
 
1369
                                     brace_counts,
 
1370
                                     Quote);
 
1371
                preferRE = true;
 
1372
                // Skip one
 
1373
                advance_char(i, ch, chNext, chNext2);
1202
1374
            }
1203
1375
        }
1204
1376
            
1469
1641
            if (foldComment && stylePrev != SCE_RB_COMMENTLINE) {
1470
1642
                if (chNext == '{') {
1471
1643
                                        levelCurrent++;
1472
 
                                } else if (chNext == '}') {
 
1644
                                } else if (chNext == '}' && levelCurrent > 0) {
1473
1645
                                        levelCurrent--;
1474
1646
                                }
1475
1647
            }
1520
1692
                        visibleChars++;
1521
1693
            buffer_ends_with_eol = false;
1522
1694
        }
 
1695
                stylePrev = style;
1523
1696
    }
1524
1697
        // Fill in the real level of the next line, keeping the current flags as they will be filled in later
1525
1698
    if (!buffer_ends_with_eol) {