aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2014-08-20 16:03:07 +1000
committerNeil <nyamatongwe@gmail.com>2014-08-20 16:03:07 +1000
commitfd0d37b935d5fc143983ce49e24045deadd65083 (patch)
treef354bf8f5240e916b306e76047c571edd0d0a436
parentbfa49e19fad49f41b5bf9020d192e0fad1e9e664 (diff)
downloadscintilla-mirror-fd0d37b935d5fc143983ce49e24045deadd65083.tar.gz
Bug [#1527]. Support block comments in VHDL.
From danselmi.
-rw-r--r--doc/ScintillaHistory.html6
-rw-r--r--include/SciLexer.h1
-rw-r--r--include/Scintilla.iface1
-rw-r--r--lexers/LexVHDL.cxx76
4 files changed, 73 insertions, 11 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html
index 1640dd0ff..f9c9b3eb0 100644
--- a/doc/ScintillaHistory.html
+++ b/doc/ScintillaHistory.html
@@ -455,6 +455,8 @@
<td>Nick Gravgaard</td>
<td>Ian Goldby</td>
<td>Holger Stenger</td>
+ </tr><tr>
+ <td>danselmi</td>
</tr>
</table>
<p>
@@ -474,6 +476,10 @@
Released 13 August 2014.
</li>
<li>
+ VHDL lexer supports block comments.
+ <a href="http://sourceforge.net/p/scintilla/bugs/1527/">Bug #1527</a>.
+ </li>
+ <li>
On Windows only unregister windows classes registered.
<a href="http://sourceforge.net/p/scintilla/bugs/1639/">Bug #1639</a>.
</li>
diff --git a/include/SciLexer.h b/include/SciLexer.h
index b45ed9474..11eaf7b5e 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -1004,6 +1004,7 @@
#define SCE_VHDL_STDPACKAGE 12
#define SCE_VHDL_STDTYPE 13
#define SCE_VHDL_USERWORD 14
+#define SCE_VHDL_BLOCK_COMMENT 15
#define SCE_CAML_DEFAULT 0
#define SCE_CAML_IDENTIFIER 1
#define SCE_CAML_TAGNAME 2
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index ec047f2d4..e6fbd02f8 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -3703,6 +3703,7 @@ val SCE_VHDL_STDFUNCTION=11
val SCE_VHDL_STDPACKAGE=12
val SCE_VHDL_STDTYPE=13
val SCE_VHDL_USERWORD=14
+val SCE_VHDL_BLOCK_COMMENT=15
# Lexical states for SCLEX_CAML
lex Caml=SCLEX_CAML SCE_CAML_
val SCE_CAML_DEFAULT=0
diff --git a/lexers/LexVHDL.cxx b/lexers/LexVHDL.cxx
index 189416425..36307a77f 100644
--- a/lexers/LexVHDL.cxx
+++ b/lexers/LexVHDL.cxx
@@ -119,6 +119,11 @@ static void ColouriseVHDLDoc(
sc.ChangeState(SCE_VHDL_STRINGEOL);
sc.ForwardSetState(SCE_VHDL_DEFAULT);
}
+ } else if (sc.state == SCE_VHDL_BLOCK_COMMENT){
+ if(sc.ch == '*' && sc.chNext == '/'){
+ sc.Forward();
+ sc.ForwardSetState(SCE_VHDL_DEFAULT);
+ }
}
// Determine if a new state should be entered.
@@ -132,6 +137,8 @@ static void ColouriseVHDLDoc(
sc.SetState(SCE_VHDL_COMMENTLINEBANG);
else
sc.SetState(SCE_VHDL_COMMENT);
+ } else if (sc.Match('/', '*')){
+ sc.SetState(SCE_VHDL_BLOCK_COMMENT);
} else if (sc.ch == '\"') {
sc.SetState(SCE_VHDL_STRING);
} else if (isoperator(static_cast<char>(sc.ch))) {
@@ -155,6 +162,39 @@ static bool IsCommentLine(int line, Accessor &styler) {
}
return false;
}
+static bool IsCommentBlockStart(int line, Accessor &styler)
+{
+ int pos = styler.LineStart(line);
+ int eol_pos = styler.LineStart(line + 1) - 1;
+ for (int i = pos; i < eol_pos; i++) {
+ char ch = styler[i];
+ char chNext = styler[i+1];
+ char style = styler.StyleAt(i);
+ if ((style == SCE_VHDL_BLOCK_COMMENT) && (ch == '/') && (chNext == '*'))
+ return true;
+ }
+ return false;
+}
+
+static bool IsCommentBlockEnd(int line, Accessor &styler)
+{
+ int pos = styler.LineStart(line);
+ int eol_pos = styler.LineStart(line + 1) - 1;
+
+ for (int i = pos; i < eol_pos; i++) {
+ char ch = styler[i];
+ char chNext = styler[i+1];
+ char style = styler.StyleAt(i);
+ if ((style == SCE_VHDL_BLOCK_COMMENT) && (ch == '*') && (chNext == '/'))
+ return true;
+ }
+ return false;
+}
+
+static bool IsCommentStyle(char style)
+{
+ return style == SCE_VHDL_BLOCK_COMMENT || style == SCE_VHDL_COMMENT || style == SCE_VHDL_COMMENTLINEBANG;
+}
//=============================================================================
// Folding the code
@@ -207,14 +247,14 @@ static void FoldNoBoxVHDLDoc(
char chPrev = styler.SafeGetCharAt(j-1);
int style = styler.StyleAt(j);
int stylePrev = styler.StyleAt(j-1);
- if ((stylePrev != SCE_VHDL_COMMENT) && (stylePrev != SCE_VHDL_STRING))
+ if ((!IsCommentStyle(style)) && (stylePrev != SCE_VHDL_STRING))
{
if(IsAWordChar(chPrev) && !IsAWordChar(ch))
{
end = j-1;
}
}
- if ((style != SCE_VHDL_COMMENT) && (style != SCE_VHDL_STRING))
+ if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
{
if(!IsAWordChar(chPrev) && IsAWordStart(ch) && (end != 0))
{
@@ -236,7 +276,7 @@ static void FoldNoBoxVHDLDoc(
{
char ch = styler.SafeGetCharAt(j);
int style = styler.StyleAt(j);
- if ((style != SCE_VHDL_COMMENT) && (style != SCE_VHDL_STRING))
+ if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
{
if((ch == ';') && (strcmp(prevWord, "end") == 0))
{
@@ -268,15 +308,29 @@ static void FoldNoBoxVHDLDoc(
styleNext = styler.StyleAt(i + 1);
bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
- if (foldComment && atEOL && IsCommentLine(lineCurrent, styler))
+ if (foldComment && atEOL)
{
- if(!IsCommentLine(lineCurrent-1, styler) && IsCommentLine(lineCurrent+1, styler))
+ if(IsCommentLine(lineCurrent, styler))
{
- levelNext++;
+ if(!IsCommentLine(lineCurrent-1, styler) && IsCommentLine(lineCurrent+1, styler))
+ {
+ levelNext++;
+ }
+ else if(IsCommentLine(lineCurrent-1, styler) && !IsCommentLine(lineCurrent+1, styler))
+ {
+ levelNext--;
+ }
}
- else if(IsCommentLine(lineCurrent-1, styler) && !IsCommentLine(lineCurrent+1, styler))
+ else
{
- levelNext--;
+ if (IsCommentBlockStart(lineCurrent, styler) && !IsCommentBlockEnd(lineCurrent, styler))
+ {
+ levelNext++;
+ }
+ else if (IsCommentBlockEnd(lineCurrent, styler) && !IsCommentBlockStart(lineCurrent, styler))
+ {
+ levelNext--;
+ }
}
}
@@ -289,7 +343,7 @@ static void FoldNoBoxVHDLDoc(
}
}
- if ((style != SCE_VHDL_COMMENT) && (style != SCE_VHDL_STRING))
+ if ((!IsCommentStyle(style)) && (style != SCE_VHDL_STRING))
{
if((ch == ';') && (strcmp(prevWord, "end") == 0))
{
@@ -301,7 +355,7 @@ static void FoldNoBoxVHDLDoc(
lastStart = i;
}
- if(iswordchar(ch) && !iswordchar(chNext)) {
+ if(IsAWordChar(ch) && !IsAWordChar(chNext)) {
char s[32];
unsigned int k;
for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++) {
@@ -346,7 +400,7 @@ static void FoldNoBoxVHDLDoc(
if(LocalCh == ')') BracketLevel--;
if(
(BracketLevel == 0) &&
- (LocalStyle != SCE_VHDL_COMMENT) &&
+ (!IsCommentStyle(LocalStyle)) &&
(LocalStyle != SCE_VHDL_STRING) &&
!iswordchar(styler.SafeGetCharAt(j-1)) &&
styler.Match(j, "is") &&