[svn] r7617: vs-plugin/trunk:
Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
Nemerle.Com...
IT
svnadmin at nemerle.org
Tue Apr 24 05:14:20 CEST 2007
Log:
Recursive String colorizing.
Author: IT
Date: Tue Apr 24 05:14:16 2007
New Revision: 7617
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanState.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n Tue Apr 24 05:14:16 2007
@@ -48,11 +48,14 @@
base.eating_now = 0;
_env = if (env != null) env else Manager.CoreEnv;
+
when (typeBuilder != null)
_typeBuilder = typeBuilder;
+
_onPreprocessor = false;
_tokenInfo.Token = null;
_bracketCount = -1;
+ _recursiveStringCount = -1;
_quotationCount = -1;
_tokenInfo.IsEndOfLine = eol();
@@ -70,6 +73,7 @@
mutable _onPreprocessor : bool;
mutable _keepDollar : bool;
mutable _bracketCount : int;
+ mutable _recursiveStringCount : int;
mutable _quotationCount : int;
mutable _identifiers : list[string] = [];
@@ -194,10 +198,9 @@
private SColor(isEx : bool) : C
{
- if (isEx)
- if (_tokenInfo.IsMultiLineString) C.VerbatimStringEx else C.StringEx
- else
- if (_tokenInfo.IsMultiLineString) C.VerbatimString else C.String
+ if (_tokenInfo.IsMultiLineString) if (isEx) C.VerbatimStringEx else C.VerbatimString
+ else if (_tokenInfo.IsRecursiveString) if (isEx) C.RecursiveStringEx else C.RecursiveString
+ else if (isEx) C.StringEx else C.String
}
private GetStringToken() : Token * ScanTokenType * ScanTokenColor * ScanTokenTriggers
@@ -205,6 +208,9 @@
when (_tokenInfo.IsDollar && _bracketCount < 0)
_bracketCount = _tokenInfo.BracketCount;
+ when (_tokenInfo.IsRecursiveString && _recursiveStringCount < 0)
+ _recursiveStringCount = _tokenInfo.RecursiveCount;
+
def getDollarContent()
{
def loop()
@@ -233,11 +239,23 @@
skip();
loop();
- | '"' =>
+ | '"' when !_tokenInfo.IsRecursiveString =>
- _Debug("");
_tokenInfo.State &= ~(ScanState.String | ScanState.MultiLineString);
+ | '#' when _tokenInfo.IsRecursiveString && peek() == '>' =>
+
+ _recursiveStringCount--;
+ _tokenInfo.RecursiveCount = _recursiveStringCount;
+
+ if (_recursiveStringCount == 0)
+ _tokenInfo.State &= ~(ScanState.String | ScanState.RecursiveString);
+ else
+ {
+ skip();
+ loop();
+ }
+
| '\0' => ()
| _ => loop()
}
@@ -260,7 +278,7 @@
repeat (2) skip();
(Token.StringLiteral(CurrentValue), TP.String, SColor(true), TR.None)
- | '"' =>
+ | '"' when !_tokenInfo.IsRecursiveString =>
skip();
@@ -269,6 +287,34 @@
_tokenInfo.State &= ~(ScanState.String | ScanState.MultiLineString);
(Token.StringLiteral(CurrentValue), TP.String, c, TR.None)
+ | '#' when _tokenInfo.IsRecursiveString && peek_next() == '>' =>
+
+ repeat (2) skip();
+
+ _recursiveStringCount--;
+ _tokenInfo.RecursiveCount = _recursiveStringCount;
+
+ if (_recursiveStringCount == 0)
+ {
+ def c = SColor(false);
+
+ _tokenInfo.State &= ~(ScanState.String | ScanState.RecursiveString);
+ (Token.StringLiteral(CurrentValue), TP.String, c, TR.None)
+ }
+ else
+ {
+ GetStringToken();
+ }
+
+ | '<' when _tokenInfo.IsRecursiveString && peek_next() == '#' =>
+
+ repeat (2) skip();
+
+ _recursiveStringCount++;
+ _tokenInfo.RecursiveCount = _recursiveStringCount;
+
+ (Token.StringLiteral(CurrentValue), TP.String, SColor(false), TR.None)
+
| '\\' when !_tokenInfo.IsMultiLineString =>
skip();
@@ -342,7 +388,13 @@
skip();
match (peek())
{
- | '"' | '\\' | '{' | '$' when _tokenInfo.IsDollar | '\0' => ()
+ | '"'
+ | '\\'
+ | '{'
+ | '$' when _tokenInfo.IsDollar
+ | '#' when _tokenInfo.IsRecursiveString
+ | '<' when _tokenInfo.IsRecursiveString
+ | '\0' => ()
| _ => loop()
}
}
@@ -584,7 +636,7 @@
public GetToken(prevState : ScanState) : ScanTokenInfo
{
- if(_pendingToken != null)
+ if (_pendingToken != null)
{
def tmp = _pendingToken;
_pendingToken = null;
@@ -612,6 +664,11 @@
_tokenInfo.ColorizeEnd = true;
C.VerbatimString
}
+ else if (_tokenInfo.IsRecursiveString)
+ {
+ _tokenInfo.ColorizeEnd = true;
+ C.RecursiveString
+ }
else if (_tokenInfo.IsQuotation)
{
_tokenInfo.ColorizeEnd = true;
@@ -655,6 +712,14 @@
_tokenInfo.State |= (ScanState.String | ScanState.MultiLineString);
repeat (2) skip();
+ | '<' =>
+
+ _recursiveStringCount = 1;
+ _tokenInfo.RecursiveCount = _recursiveStringCount;
+ _tokenInfo.State |= (ScanState.String | ScanState.RecursiveString);
+
+ repeat (2) skip();
+
| _ => throw InvalidOperationException()
}
@@ -712,7 +777,12 @@
else
GetBaseToken();
- | '"' | '@' when peek_next() == '"' =>
+ | '"'
+ | '@' when peek_next() == '"'
+ | '<' when peek_next() == '#' =>
+
+ // HACK: We always colorize $.
+ _tokenInfo.State |= ScanState.Dollar;
getString();
@@ -728,7 +798,8 @@
_tokenInfo.State |= ScanState.Dollar;
(Token.Operator(CurrentValue), TP.Operator, C.Operator, TR.None)
- | '"' | '@' when peek_next() == '"' =>
+ | '"' | '@' when peek_next() == '"'
+ | '<' | '#' when peek_next() == '"' =>
_tokenInfo.State &= ~ScanState.BracketCounter;
_tokenInfo.State |= ScanState.Dollar;
@@ -751,7 +822,6 @@
when (resetQuotationStart && !_tokenInfo.IsWhiteSpaceOrCommentType)
_tokenInfo.State &= ~ScanState.QuotationStart;
-
when (_tokenInfo.IsQuotation && !(_tokenInfo.Token is Token.BeginQuote))
{
_tokenInfo.Color = match (_tokenInfo.Color)
@@ -766,6 +836,8 @@
| StringEx => ScanTokenColor.QuotationStringEx
| VerbatimString => ScanTokenColor.QuotationVerbatimString
| VerbatimStringEx => ScanTokenColor.QuotationVerbatimStringEx
+ | RecursiveString => ScanTokenColor.QuotationRecursiveString
+ | RecursiveStringEx => ScanTokenColor.QuotationRecursiveStringEx
| UserType => ScanTokenColor.QuotationUserType
| UserTypeDelegate => ScanTokenColor.QuotationUserTypeDelegate
| UserTypeEnum => ScanTokenColor.QuotationUserTypeEnum
@@ -796,8 +868,6 @@
(ScanTokenColor.CommentHACK, Regex(@"(\b(HACK)\b\s*:.*)", RegexOptions.Compiled))
];
-;
-
CheckForSpecialComments(tokenInfo : ScanTokenInfo) : void
{
def chooseColor(str, regexList)
@@ -817,9 +887,11 @@
match(tokenInfo.Token)
{
| Comment(value) =>
+
//TODO: Implement special comment in the middle of regular one, ie // regular >special one< regular again
def commentWOBeginning = value.Substring(2);
def (idx, len, color) = chooseColor(commentWOBeginning, specialCommentRegexes);
+
when(idx != -1)
{
_pendingToken = tokenInfo.Clone();
@@ -831,9 +903,11 @@
_pendingToken.Color = color;
_pendingToken.Token.Location = Location(l, l.Line, l.Column + 2 + idx, l.EndLine, l.EndColumn);
}
+
| _ => ()
}
}
+
#endregion
checkForHighlights(tokenInfo : ScanTokenInfo) : bool
@@ -931,14 +1005,16 @@
public AddHighlighting(highlights : list[Location * int]) : void
{
def groups = highlights.Group(
- (one : Location * int, two : Location * int) => {
+ (one : Location * int, two : Location * int) =>
+ {
def (locationOne, _) = one;
def (locationTwo, _) = two;
+
locationOne.Line - locationTwo.Line
- }
- ).Map(locationsOnTheLine =>
+ }).Map(locationsOnTheLine =>
(locationsOnTheLine.Head[0].Line, locationsOnTheLine.Map(
(l, color) => (Location(0, l.Line, l.Column, l.EndLine, l.EndColumn), color))));
+
unless (groups.IsEmpty)
{
def newHighlight = Hashtable();
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanState.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanState.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanState.n Tue Apr 24 05:14:16 2007
@@ -12,6 +12,8 @@
| Dollar = 0x00000010
| String = 0x00000020
| MultiLineString = 0x00000040
+ | RecursiveString = 0x00000080
+ | RecursiveCounter = 0x00F00000
| BracketCounter = 0x0F000000
| QuotationCounter = 0xF0000000
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenColor.n Tue Apr 24 05:14:16 2007
@@ -49,5 +49,10 @@
| CommentTODO
| CommentBUG
| CommentHACK
+
+ | RecursiveString
+ | RecursiveStringEx
+ | QuotationRecursiveString
+ | QuotationRecursiveStringEx
}
}
Modified: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n
==============================================================================
--- vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n (original)
+++ vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanTokenInfo.n Tue Apr 24 05:14:16 2007
@@ -15,6 +15,18 @@
public mutable IsEndOfLine : bool;
public mutable ColorizeEnd : bool;
+ public RecursiveCount : int
+ {
+ get { (State & ScanState.RecursiveCounter) :> int >> 20 }
+ set
+ {
+ def val = if (value > 0xF) 0xF else value;
+
+ State &= ~ScanState.RecursiveCounter;
+ State |= (val << 20) :> ScanState;
+ }
+ }
+
public BracketCount : int
{
get { (State & ScanState.BracketCounter) :> int >> 24 }
@@ -44,6 +56,7 @@
public IsComment : bool { get { State %&& ScanState.Comment } }
public IsString : bool { get { State %&& ScanState.String } }
public IsMultiLineString : bool { get { State %&& ScanState.MultiLineString } }
+ public IsRecursiveString : bool { get { State %&& ScanState.RecursiveString } }
public IsDollar : bool { get { State %&& ScanState.Dollar } }
public IsWhiteSpaceType : bool { get { Type == ScanTokenType.WhiteSpace } }
Modified: vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs
==============================================================================
--- vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs (original)
+++ vs-plugin/trunk/Nemerle.VsIntegration/LanguageService/NemerleLanguageService.cs Tue Apr 24 05:14:16 2007
@@ -819,7 +819,12 @@
new NemerleColorableItem("TODO comment", COLORINDEX.CI_BLUE, Color.FromArgb(0, 175, 255)),
new NemerleColorableItem("BUG comment", COLORINDEX.CI_RED, Color.FromArgb(255, 75, 75), FONTFLAGS.FF_BOLD),
- new NemerleColorableItem("HACK comment", COLORINDEX.CI_RED, Color.FromArgb(145, 0, 0))
+ new NemerleColorableItem("HACK comment", COLORINDEX.CI_RED, Color.FromArgb(145, 0, 0)),
+
+ new NemerleColorableItem("String (<# #>)", 2, COLORINDEX.CI_MAROON, Color.FromArgb(170, 0, 0)),
+ new NemerleColorableItem("StringEx (<# #>)", 2, COLORINDEX.CI_MAROON, Color.FromArgb(143, 44, 182)),
+ new NemerleColorableItem("<[ String (<# #>) ]>", 1, COLORINDEX.CI_MAROON, Color.FromArgb(170, 0, 0)),
+ new NemerleColorableItem("<[ StringEx (<# #>) ]>", 1, COLORINDEX.CI_MAROON, Color.FromArgb(143, 44, 182)),
};
Dictionary<IVsTextLines, NemerleColorizer> _colorizers = new Dictionary<IVsTextLines,NemerleColorizer>();
More information about the svn
mailing list