[svn]
r6757: vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
IT
svnadmin at nemerle.org
Fri Oct 13 22:42:55 CEST 2006
Log:
ScanLexer. Finished preprocessor colorizing.
Author: IT
Date: Fri Oct 13 22:42:53 2006
New Revision: 6757
Modified:
vs-plugin/trunk/Nemerle.Compiler.Utils/Nemerle.Completion2/CodeModel/ScanLexer.n
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 Fri Oct 13 22:42:53 2006
@@ -71,6 +71,12 @@
mutable _last_col : int;
mutable _onPreprocessor : bool;
+ private SkipToEnd() : void
+ {
+ pos = reader.Length;
+ col = pos + 1;
+ }
+
private FindEndOfComment() : Token.Comment
{
def idx = reader.IndexOf("*/", pos);
@@ -79,15 +85,14 @@
{
_tokenInfo.ScanState &= ~ScanState.Comment;
pos = idx + 2;
+ col = pos + 1;
}
else
{
_tokenInfo.ScanState |= ScanState.Comment;
- pos = reader.Length;
+ SkipToEnd();
}
- col = pos + 1;
-
Token.Comment(reader.Substring(_last_col - 1, col - _last_col));
}
@@ -99,9 +104,7 @@
{
| '/' =>
- pos = reader.Length;
- col = pos + 1;
-
+ SkipToEnd();
Token.Comment(reader.Substring(_last_col - 1));
| '*' =>
@@ -115,17 +118,62 @@
private GetPreprocessorToken() : Token
{
+ mutable last_col;
+
+ def readWord() : string
+ {
+ while (Char.IsWhiteSpace(peek()))
+ _ = read();
+
+ last_col = col;
+
+ for (mutable c = peek(); IsIdBeginning(c) || Char.IsDigit(c); c = peek())
_ = read();
- Token.Keyword("#");
+ reader.Substring(last_col - 1, col - last_col);
}
- public GetToken(prevState : ScanState) : ScanTokenInfo
+ match (readWord())
{
- _last_line = line;
- _last_col = col;
+ | "if" | "elif" | "else" | "endif"
+ | "error" | "warning"
+ | "region" | "endregion"
+ | "define" | "undef" =>
+
+ last_col = col;
+
+ | "line" =>
+
+ last_col = col;
+ when (readWord() == "default")
+ last_col = col
- def getBaseToken()
+ | "pragma" =>
+
+ last_col = col;
+
+ match (readWord())
+ {
+ | "indent" => last_col = col;
+ | "warning" => last_col = col;
+
+ match (readWord())
+ {
+ | "disable" | "restore" => last_col = col
+ | _ => ()
+ }
+ | _ => ()
+ }
+ | _ => ()
+ }
+
+ col = last_col;
+ pos = col - 1;
+
+ Token.Keyword(reader.Substring(_last_col - 1, col - _last_col));
+ }
+
+ private GetBaseToken() : Token * ScanTokenType * ScanTokenColor * ScanTokenTriggers
{
def tok = base.GetToken();
@@ -162,19 +210,24 @@
(tok, tp, color, trigger)
}
- when (reader == " 0")
+ public GetToken(prevState : ScanState) : ScanTokenInfo
{
- def _s = reader.Substring(pos);
- }
-
_tokenInfo.ScanState = prevState;
+ _last_line = line;
+ _last_col = col;
+
(_tokenInfo.Token, _tokenInfo.Type, _tokenInfo.Color, _tokenInfo.Triggers)
=
if (pos >= reader.Length)
{
(Token.EndOfFile(), TP.Unknown, C.Text, TR.None)
}
+ else if (_onPreprocessor)
+ {
+ SkipToEnd();
+ (Token.Identifier(""), TP.Unknown, C.Text, TR.None)
+ }
else if ((prevState & ScanState.Comment) != 0)
{
(FindEndOfComment(), TP.Comment, C.Comment, TR.None)
@@ -191,7 +244,7 @@
tok,
TP.WhiteSpace,
C.Text,
- if (pos+1 >= reader.Length && (tok :> Token.WhiteSpace).value == "")
+ if (pos >= reader.Length && (tok :> Token.WhiteSpace).value == " ")
match (_tokenInfo.Token)
{
| Keyword (name) when name == "using"
@@ -209,7 +262,10 @@
_ = read();
+ if (pos >= reader.Length)
(Token.Keyword("#"), TP.Keyword, C.Keyword, TR.MemberSelect)
+ else
+ (GetPreprocessorToken(), TP.Keyword, C.Keyword, TR.None)
| '/' =>
@@ -218,9 +274,9 @@
if (tok != null)
(tok, TP.Comment, C.Comment, TR.None)
else
- getBaseToken();
+ GetBaseToken();
- | _ => getBaseToken();
+ | _ => GetBaseToken();
}
}
More information about the svn
mailing list