Mercurial > mxe-octave
comparison src/qscintilla-1-matlab-blockcomments.patch @ 3065:7f1d390cbd83
Add QScintilla blockcomments patch
* src/qscintilla-1-matlab-blockcomments.patch: New file
* src/qscintilla.mk: change PKG_SUBDIR to base of tarball so patch works, and change PKG_BUILD to (1)/Qt4Qt5.
author | John Donoghue <john.donoghue@ieee.org> |
---|---|
date | Tue, 18 Jun 2013 18:34:53 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3064:be70678cc47b | 3065:7f1d390cbd83 |
---|---|
1 diff -p -u -r QScintilla-gpl-2.7.2-snapshot-0714ef531ead.orig/lexers/LexMatlab.cpp QScintilla-gpl-2.7.2-snapshot-0714ef531ead/lexers/LexMatlab.cpp | |
2 --- QScintilla-gpl-2.7.2-snapshot-0714ef531ead.orig/lexers/LexMatlab.cpp 2013-05-14 20:55:15.000000000 -0400 | |
3 +++ QScintilla-gpl-2.7.2-snapshot-0714ef531ead/lexers/LexMatlab.cpp 2013-05-14 20:56:15.000000000 -0400 | |
4 @@ -6,6 +6,12 @@ | |
5 ** Changes by Christoph Dalitz 2003/12/04: | |
6 ** - added support for Octave | |
7 ** - Strings can now be included both in single or double quotes | |
8 + ** | |
9 + ** Changes by John Donoghue 2012/04/02 | |
10 + ** - added block comment (and nested block comments) | |
11 + ** - added ... displayed as a comment | |
12 + ** - removed unused IsAWord functions | |
13 + ** - added some comments | |
14 **/ | |
15 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> | |
16 // The License.txt file describes the conditions under which this software may be distributed. | |
17 @@ -48,14 +54,6 @@ static bool IsOctaveComment(Accessor &st | |
18 return len > 0 && IsOctaveCommentChar(styler[pos]) ; | |
19 } | |
20 | |
21 -static inline bool IsAWordChar(const int ch) { | |
22 - return (ch < 0x80) && (isalnum(ch) || ch == '_'); | |
23 -} | |
24 - | |
25 -static inline bool IsAWordStart(const int ch) { | |
26 - return (ch < 0x80) && (isalnum(ch) || ch == '_'); | |
27 -} | |
28 - | |
29 static void ColouriseMatlabOctaveDoc( | |
30 unsigned int startPos, int length, int initStyle, | |
31 WordList *keywordlists[], Accessor &styler, | |
32 @@ -65,12 +63,41 @@ static void ColouriseMatlabOctaveDoc( | |
33 | |
34 styler.StartAt(startPos); | |
35 | |
36 + // boolean for when the ' is allowed to be transpose vs the start/end | |
37 + // of a string | |
38 bool transpose = false; | |
39 | |
40 + // approximate position of first non space character in a line | |
41 + int nonSpaceColumn = -1; | |
42 + // approximate column position of the current character in a line | |
43 + int column = 0; | |
44 + | |
45 + // use the line state of each line to store the block comment depth | |
46 + int curLine = styler.GetLine(startPos); | |
47 + int commentDepth = curLine > 0 ? styler.GetLineState(curLine-1) : 0; | |
48 + | |
49 + | |
50 StyleContext sc(startPos, length, initStyle, styler); | |
51 | |
52 - for (; sc.More(); sc.Forward()) { | |
53 + for (; sc.More(); sc.Forward(), column++) { | |
54 + | |
55 + if(sc.atLineStart) { | |
56 + // set the line state to the current commentDepth | |
57 + curLine = styler.GetLine(sc.currentPos); | |
58 + styler.SetLineState(curLine, commentDepth); | |
59 + | |
60 + // reset the column to 0, nonSpace to -1 (not set) | |
61 + column = 0; | |
62 + nonSpaceColumn = -1; | |
63 + } | |
64 + | |
65 + // save the column position of first non space character in a line | |
66 + if((nonSpaceColumn == -1) && (! IsASpace(sc.ch))) | |
67 + { | |
68 + nonSpaceColumn = column; | |
69 + } | |
70 | |
71 + // check for end of states | |
72 if (sc.state == SCE_MATLAB_OPERATOR) { | |
73 if (sc.chPrev == '.') { | |
74 if (sc.ch == '*' || sc.ch == '/' || sc.ch == '\\' || sc.ch == '^') { | |
75 @@ -79,6 +106,10 @@ static void ColouriseMatlabOctaveDoc( | |
76 } else if (sc.ch == '\'') { | |
77 sc.ForwardSetState(SCE_MATLAB_DEFAULT); | |
78 transpose = true; | |
79 + } else if(sc.ch == '.' && sc.chNext == '.') { | |
80 + // we werent an operator, but a '...' | |
81 + sc.ChangeState(SCE_MATLAB_COMMENT); | |
82 + transpose = false; | |
83 } else { | |
84 sc.SetState(SCE_MATLAB_DEFAULT); | |
85 } | |
86 @@ -121,15 +152,51 @@ static void ColouriseMatlabOctaveDoc( | |
87 } else if (sc.ch == '\"') { | |
88 sc.ForwardSetState(SCE_MATLAB_DEFAULT); | |
89 } | |
90 - } else if (sc.state == SCE_MATLAB_COMMENT || sc.state == SCE_MATLAB_COMMAND) { | |
91 + } else if (sc.state == SCE_MATLAB_COMMAND) { | |
92 if (sc.atLineEnd) { | |
93 sc.SetState(SCE_MATLAB_DEFAULT); | |
94 transpose = false; | |
95 } | |
96 + } else if (sc.state == SCE_MATLAB_COMMENT) { | |
97 + // end or start of a nested a block comment? | |
98 + if( IsCommentChar(sc.ch) && sc.chNext == '}' && nonSpaceColumn == column) { | |
99 + if(commentDepth > 0) commentDepth --; | |
100 + | |
101 + curLine = styler.GetLine(sc.currentPos); | |
102 + styler.SetLineState(curLine, commentDepth); | |
103 + sc.Forward(); | |
104 + | |
105 + if (commentDepth == 0) { | |
106 + sc.ForwardSetState(SCE_D_DEFAULT); | |
107 + transpose = false; | |
108 + } | |
109 + } | |
110 + else if( IsCommentChar(sc.ch) && sc.chNext == '{' && nonSpaceColumn == column) | |
111 + { | |
112 + commentDepth ++; | |
113 + | |
114 + curLine = styler.GetLine(sc.currentPos); | |
115 + styler.SetLineState(curLine, commentDepth); | |
116 + sc.Forward(); | |
117 + transpose = false; | |
118 + | |
119 + } else if(commentDepth == 0) { | |
120 + // single line comment | |
121 + if (sc.atLineEnd || sc.ch == '\r' || sc.ch == '\n') { | |
122 + sc.SetState(SCE_MATLAB_DEFAULT); | |
123 + transpose = false; | |
124 + } | |
125 + } | |
126 } | |
127 | |
128 + // check start of a new state | |
129 if (sc.state == SCE_MATLAB_DEFAULT) { | |
130 if (IsCommentChar(sc.ch)) { | |
131 + // ncrement depth if we are a block comment | |
132 + if(sc.chNext == '{' && nonSpaceColumn == column) | |
133 + commentDepth ++; | |
134 + curLine = styler.GetLine(sc.currentPos); | |
135 + styler.SetLineState(curLine, commentDepth); | |
136 sc.SetState(SCE_MATLAB_COMMENT); | |
137 } else if (sc.ch == '!' && sc.chNext != '=' ) { | |
138 sc.SetState(SCE_MATLAB_COMMAND); |