~ubuntu-branches/ubuntu/maverick/codelite/maverick

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Alessio Treglia
  • Date: 2010-07-29 19:42:47 UTC
  • mfrom: (1.1.9 upstream) (18.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100729194247-cuibfk03wog33nxq
Tags: 2.6.0.4189~dfsg-1
* New upstream release.
* Bump Standards.
* Refresh patches.
* Add license information about files under ./Debugger/

Show diffs side-by-side

added added

removed removed

Lines of Context:
76
76
                char ch = static_cast<char>(styler.SafeGetCharAt(start + i));
77
77
                if ((i == 0) && !IsAWordStart(ch))
78
78
                        break;
79
 
                if ((i > 0) && !IsAWordChar(ch)) 
 
79
                if ((i > 0) && !IsAWordChar(ch))
80
80
                        break;
81
81
                s[i] = ch;
82
82
        }
83
83
        s[i] = '\0';
84
 
        
 
84
 
85
85
        return s;
86
86
}
87
87
 
494
494
        if (strlen(blockType) == 0) {
495
495
                return ((ch == '%') && (chNext == '>'));
496
496
        } else if ((0 == strcmp(blockType, "inherit")) ||
497
 
                           (0 == strcmp(blockType, "namespace")) || 
 
497
                           (0 == strcmp(blockType, "namespace")) ||
498
498
                           (0 == strcmp(blockType, "include")) ||
499
499
                           (0 == strcmp(blockType, "page"))) {
500
500
                return ((ch == '/') && (chNext == '>'));
507
507
        }
508
508
}
509
509
 
 
510
static bool isDjangoBlockEnd(const int ch, const int chNext, const char *blockType) {
 
511
        if (strlen(blockType) == 0) {
 
512
                return 0;
 
513
        } else if (0 == strcmp(blockType, "%")) {
 
514
                return ((ch == '%') && (chNext == '}'));
 
515
        } else if (0 == strcmp(blockType, "{")) {
 
516
                return ((ch == '}') && (chNext == '}'));
 
517
        } else {
 
518
                return 0;
 
519
        }
 
520
}
 
521
 
510
522
static bool isPHPStringState(int state) {
511
523
        return
512
524
            (state == SCE_HPHP_HSTRING) ||
575
587
        styler.StartAt(startPos, static_cast<char>(STYLE_MAX));
576
588
        char prevWord[200];
577
589
        prevWord[0] = '\0';
578
 
        char nextWord[200];
579
 
        nextWord[0] = '\0';
580
590
        char phpStringDelimiter[200]; // PHP is not limited in length, we are
581
591
        phpStringDelimiter[0] = '\0';
582
592
        int StateToPrint = initStyle;
583
593
        int state = stateForPrintState(StateToPrint);
584
594
        char makoBlockType[200];
585
595
        makoBlockType[0] = '\0';
 
596
        char djangoBlockType[2];
 
597
        djangoBlockType[0] = '\0';
586
598
 
587
599
        // If inside a tag, it may be a script tag, so reread from the start to ensure any language tags are seen
588
600
        if (InTagState(state)) {
612
624
                // Default client and ASP scripting language is JavaScript
613
625
                lineState = eScriptJS << 8;
614
626
 
615
 
                // property asp.default.language 
616
 
                //      Script in ASP code is initially assumed to be in JavaScript. 
 
627
                // property asp.default.language
 
628
                //      Script in ASP code is initially assumed to be in JavaScript.
617
629
                //      To change this to VBScript set asp.default.language to 2. Python is 3.
618
630
                lineState |= styler.GetPropertyInt("asp.default.language", eScriptJS) << 4;
619
631
        }
630
642
        if (inScriptType == eNonHtmlScript && state == SCE_H_COMMENT) {
631
643
                scriptLanguage = eScriptComment;
632
644
        }
 
645
        script_type beforeLanguage = ScriptOfState(beforePreProc);
633
646
 
634
 
        // property fold.html 
635
 
        //      Folding is turned on or off for HTML and XML files with this option. 
 
647
        // property fold.html
 
648
        //      Folding is turned on or off for HTML and XML files with this option.
636
649
        //      The fold option must also be on for folding to occur.
637
650
        const bool foldHTML = styler.GetPropertyInt("fold.html", 0) != 0;
638
651
 
639
652
        const bool fold = foldHTML && styler.GetPropertyInt("fold", 0);
640
653
 
641
 
        // property fold.html.preprocessor 
642
 
        //      Folding is turned on or off for scripts embedded in HTML files with this option. 
 
654
        // property fold.html.preprocessor
 
655
        //      Folding is turned on or off for scripts embedded in HTML files with this option.
643
656
        //      The default is on.
644
657
        const bool foldHTMLPreprocessor = foldHTML && styler.GetPropertyInt("fold.html.preprocessor", 1);
645
658
 
646
659
        const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
647
660
 
648
 
        // property fold.hypertext.comment 
649
 
        //      Allow folding for comments in scripts embedded in HTML. 
650
 
        //      The default is off. 
 
661
        // property fold.hypertext.comment
 
662
        //      Allow folding for comments in scripts embedded in HTML.
 
663
        //      The default is off.
651
664
        const bool foldComment = fold && styler.GetPropertyInt("fold.hypertext.comment", 0) != 0;
652
665
 
653
 
        // property fold.hypertext.heredoc 
654
 
        //      Allow folding for heredocs in scripts embedded in HTML. 
655
 
        //      The default is off.  
 
666
        // property fold.hypertext.heredoc
 
667
        //      Allow folding for heredocs in scripts embedded in HTML.
 
668
        //      The default is off.
656
669
        const bool foldHeredoc = fold && styler.GetPropertyInt("fold.hypertext.heredoc", 0) != 0;
657
670
 
658
 
        // property html.tags.case.sensitive 
659
 
        //      For XML and HTML, setting this property to 1 will make tags match in a case 
660
 
        //      sensitive way which is the expected behaviour for XML and XHTML. 
 
671
        // property html.tags.case.sensitive
 
672
        //      For XML and HTML, setting this property to 1 will make tags match in a case
 
673
        //      sensitive way which is the expected behaviour for XML and XHTML.
661
674
        const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0;
662
675
 
663
 
        // property lexer.xml.allow.scripts 
664
 
        //      Set to 0 to disable scripts in XML.  
 
676
        // property lexer.xml.allow.scripts
 
677
        //      Set to 0 to disable scripts in XML.
665
678
        const bool allowScripts = styler.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0;
666
679
 
667
 
        // property lexer.html.mako 
668
 
        //      Set to 1 to enable the mako template language.  
 
680
        // property lexer.html.mako
 
681
        //      Set to 1 to enable the mako template language.
669
682
        const bool isMako = styler.GetPropertyInt("lexer.html.mako", 0) != 0;
670
683
 
 
684
        // property lexer.html.django
 
685
        //      Set to 1 to enable the django template language.
 
686
        const bool isDjango = styler.GetPropertyInt("lexer.html.django", 0) != 0;
 
687
 
671
688
        const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true);
672
689
        const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true);
673
690
        const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true);
800
817
                if (((ch == '\r' && chNext != '\n') || (ch == '\n')) &&
801
818
                        (!isMako || (0 != strcmp(makoBlockType, "%")))) {
802
819
                }
803
 
                
 
820
 
804
821
                // generic end of script processing
805
822
                else if ((inScriptType == eNonHtmlScript) && (ch == '<') && (chNext == '/')) {
806
823
                        // Check if it's the end of the script tag (or any other HTML tag)
886
903
                }
887
904
 
888
905
                // handle the start Mako template Python code
889
 
                else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') || 
 
906
                else if (isMako && scriptLanguage == eScriptNone && ((ch == '<' && chNext == '%') ||
890
907
                                                                                                                         (lineStartVisibleChars == 1 && ch == '%') ||
891
908
                                                                                                                         (ch == '$' && chNext == '{') ||
892
909
                                                                                                                         (ch == '<' && chNext == '/' && chNext2 == '%'))) {
893
910
                        if (ch == '%')
894
911
                                strcpy(makoBlockType, "%");
895
 
                        else if (ch == '$') 
 
912
                        else if (ch == '$')
896
913
                                strcpy(makoBlockType, "{");
897
914
                        else if (chNext == '/')
898
915
                                GetNextWord(styler, i+3, makoBlockType, sizeof(makoBlockType));
917
934
                        styler.ColourTo(i, SCE_H_ASP);
918
935
                        if (foldHTMLPreprocessor && ch == '<')
919
936
                                levelCurrent++;
920
 
                                
 
937
 
921
938
                        if (ch != '%' && ch != '$') {
922
939
                                i += strlen(makoBlockType);
923
940
                                visibleChars += strlen(makoBlockType);
931
948
                        continue;
932
949
                }
933
950
 
 
951
                // handle the start Django template code
 
952
                else if (isDjango && scriptLanguage != eScriptPython && (ch == '{' && (chNext == '%' ||  chNext == '{'))) {
 
953
                        if (chNext == '%')
 
954
                                strcpy(djangoBlockType, "%");
 
955
                        else
 
956
                                strcpy(djangoBlockType, "{");
 
957
                        styler.ColourTo(i - 1, StateToPrint);
 
958
                        beforePreProc = state;
 
959
                        if (inScriptType == eNonHtmlScript)
 
960
                                inScriptType = eNonHtmlScriptPreProc;
 
961
                        else
 
962
                                inScriptType = eNonHtmlPreProc;
 
963
 
 
964
                        i += 1;
 
965
                        visibleChars += 1;
 
966
                        state = SCE_HP_START;
 
967
                        beforeLanguage = scriptLanguage;
 
968
                        scriptLanguage = eScriptPython;
 
969
                        styler.ColourTo(i, SCE_H_ASP);
 
970
                        if (foldHTMLPreprocessor && chNext == '%')
 
971
                                levelCurrent++;
 
972
 
 
973
                        ch = static_cast<unsigned char>(styler.SafeGetCharAt(i));
 
974
                        continue;
 
975
                }
 
976
 
934
977
                // handle the start of ASP pre-processor = Non-HTML
935
 
                else if (!isMako && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
 
978
                else if (!isMako && !isDjango && !isCommentASPState(state) && (ch == '<') && (chNext == '%') && !isPHPStringState(state)) {
936
979
                        styler.ColourTo(i - 1, StateToPrint);
937
980
                        beforePreProc = state;
938
981
                        if (inScriptType == eNonHtmlScript)
998
1041
                }
999
1042
 
1000
1043
                // handle the end of Mako Python code
1001
 
                else if (isMako && 
1002
 
                             ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) && 
 
1044
                else if (isMako &&
 
1045
                             ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
1003
1046
                                 (scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
1004
1047
                                 isMakoBlockEnd(ch, chNext, makoBlockType)) {
1005
1048
                        if (state == SCE_H_ASPAT) {
1030
1073
                        continue;
1031
1074
                }
1032
1075
 
 
1076
                // handle the end of Django template code
 
1077
                else if (isDjango &&
 
1078
                             ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
 
1079
                                 (scriptLanguage != eScriptNone) && stateAllowsTermination(state) &&
 
1080
                                 isDjangoBlockEnd(ch, chNext, djangoBlockType)) {
 
1081
                        if (state == SCE_H_ASPAT) {
 
1082
                                aspScript = segIsScriptingIndicator(styler,
 
1083
                                                                    styler.GetStartSegment(), i - 1, aspScript);
 
1084
                        }
 
1085
                        if (state == SCE_HP_WORD) {
 
1086
                                classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType);
 
1087
                        } else {
 
1088
                                styler.ColourTo(i - 1, StateToPrint);
 
1089
                        }
 
1090
                        i += 1;
 
1091
                        visibleChars += 1;
 
1092
                        styler.ColourTo(i, SCE_H_ASP);
 
1093
                        state = beforePreProc;
 
1094
                        if (inScriptType == eNonHtmlScriptPreProc)
 
1095
                                inScriptType = eNonHtmlScript;
 
1096
                        else
 
1097
                                inScriptType = eHtml;
 
1098
                        if (foldHTMLPreprocessor) {
 
1099
                                levelCurrent--;
 
1100
                        }
 
1101
                        scriptLanguage = beforeLanguage;
 
1102
                        continue;
 
1103
                }
 
1104
 
1033
1105
                // handle the end of a pre-processor = Non-HTML
1034
 
                else if ((!isMako && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
 
1106
                else if ((!isMako && !isDjango && ((inScriptType == eNonHtmlPreProc) || (inScriptType == eNonHtmlScriptPreProc)) &&
1035
1107
                                  (((scriptLanguage != eScriptNone) && stateAllowsTermination(state))) &&
1036
1108
                                  (((ch == '%') || (ch == '?')) && (chNext == '>'))) ||
1037
1109
                         ((scriptLanguage == eScriptSGML) && (ch == '>') && (state != SCE_H_SGML_COMMENT))) {