From 9c38cba4055ac8e4cd9fd92774c2c46e50c3bcf7 Mon Sep 17 00:00:00 2001 From: John Donoghue Date: Thu, 29 Jun 2017 07:54:05 -0400 Subject: Bug [#1951]. matlab lexer - dont use 'end' as a keyword when used as a index. (ColouriseMatlabOctaveDoc) - set end as a number if within brackets ()[]{} that would allow end as an index rather than a keyword. --- lexers/LexMatlab.cxx | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'lexers') diff --git a/lexers/LexMatlab.cxx b/lexers/LexMatlab.cxx index 45f0b6926..a0e3ea937 100644 --- a/lexers/LexMatlab.cxx +++ b/lexers/LexMatlab.cxx @@ -100,6 +100,9 @@ static void ColouriseMatlabOctaveDoc( // of a string bool transpose = false; + // count of brackets as boolean for when end could be an operator not a keyword + int allow_end_op = 0; + // approximate position of first non space character in a line int nonSpaceColumn = -1; // approximate column position of the current character in a line @@ -153,7 +156,11 @@ static void ColouriseMatlabOctaveDoc( if (!isalnum(sc.ch) && sc.ch != '_') { char s[100]; sc.GetCurrentLowered(s, sizeof(s)); + if (keywords.InList(s)) { + if (strcmp ("end", s) == 0 && allow_end_op) { + sc.ChangeState(SCE_MATLAB_NUMBER); + } sc.SetState(SCE_MATLAB_DEFAULT); transpose = false; } else { @@ -253,6 +260,12 @@ static void ColouriseMatlabOctaveDoc( } else if (isalpha(sc.ch)) { sc.SetState(SCE_MATLAB_KEYWORD); } else if (isoperator(static_cast(sc.ch)) || sc.ch == '@' || sc.ch == '\\') { + if (sc.ch == '(' || sc.ch == '[' || sc.ch == '{') { + allow_end_op ++; + } else if ((sc.ch == ')' || sc.ch == ']' || sc.ch == '}') && (allow_end_op > 0)) { + allow_end_op --; + } + if (sc.ch == ')' || sc.ch == ']' || sc.ch == '}') { transpose = true; } else { -- cgit v1.2.3