Browse Source

worked on VB Positions, added some C# tests

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@303 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Andrea Paatz 21 years ago
parent
commit
937991a230
  1. 6
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  2. 12
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  3. 41
      src/Libraries/NRefactory/Test/Lexer/CSharp/LexerPositionTests.cs
  4. 14
      src/Libraries/NRefactory/Test/Lexer/VBNet/LexerPositionTests.cs

6
src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs

@ -78,7 +78,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
return ReadVerbatimString(); return ReadVerbatimString();
} }
if (Char.IsLetterOrDigit(ch)) { if (Char.IsLetterOrDigit(ch)) {
return new Token(Tokens.Identifier, x, y, ReadIdent(ch)); return new Token(Tokens.Identifier, x - 1, y, ReadIdent(ch));
} }
errors.Error(y, x, String.Format("Unexpected char in Lexer.Next() : {0}", ch)); errors.Error(y, x, String.Format("Unexpected char in Lexer.Next() : {0}", ch));
} }
@ -169,7 +169,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
ReaderRead(); ReaderRead();
peek = (char)ReaderPeek(); peek = (char)ReaderPeek();
if (!Char.IsDigit(peek)) { if (!Char.IsDigit(peek)) {
nextToken = new Token(Tokens.Dot, x, y); nextToken = new Token(Tokens.Dot, Col - 1, Line);
peek = '.'; peek = '.';
} else { } else {
isdouble = true; // double is default isdouble = true; // double is default
@ -493,7 +493,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadOperator(char ch) Token ReadOperator(char ch)
{ {
int x = Col; int x = Col - 1;
int y = Line; int y = Line;
switch (ch) { switch (ch) {
case '+': case '+':

12
src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs

@ -58,7 +58,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
while ((nextChar = ReaderRead()) != -1) { while ((nextChar = ReaderRead()) != -1) {
char ch = (char)nextChar; char ch = (char)nextChar;
if (Char.IsWhiteSpace(ch)) { if (Char.IsWhiteSpace(ch)) {
int x = Col; int x = Col - 1;
int y = Line; int y = Line;
if (HandleLineEnd(ch)) { if (HandleLineEnd(ch)) {
if (!lineEnd) { if (!lineEnd) {
@ -74,7 +74,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
return new Token(Tokens.EOF); return new Token(Tokens.EOF);
} }
if (!Char.IsWhiteSpace((char)ReaderPeek())) { if (!Char.IsWhiteSpace((char)ReaderPeek())) {
int x = Col; int x = Col - 1;
int y = Line; int y = Line;
string s = ReadIdent('_'); string s = ReadIdent('_');
lineEnd = false; lineEnd = false;
@ -104,7 +104,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
ReaderRead(); ReaderRead();
} }
if (Char.IsDigit((char)ReaderPeek())) { if (Char.IsDigit((char)ReaderPeek())) {
int x = Col; int x = Col - 1;
int y = Line; int y = Line;
string s = ReadDate(); string s = ReadDate();
DateTime time = new DateTime(1, 1, 1, 0, 0, 0); DateTime time = new DateTime(1, 1, 1, 0, 0, 0);
@ -167,7 +167,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
if (Char.IsDigit(ch)) { if (Char.IsDigit(ch)) {
lineEnd = false; lineEnd = false;
return ReadDigit(ch, Col); return ReadDigit(ch, Col - 1);
} }
if (ch == '&') { if (ch == '&') {
lineEnd = false; lineEnd = false;
@ -176,7 +176,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
ch = (char)ReaderPeek(); ch = (char)ReaderPeek();
if (Char.ToUpper(ch) == 'H' || Char.ToUpper(ch) == 'O') { if (Char.ToUpper(ch) == 'H' || Char.ToUpper(ch) == 'O') {
return ReadDigit('&', Col); return ReadDigit('&', Col - 1);
} }
return ReadOperator('&'); return ReadOperator('&');
} }
@ -559,7 +559,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
Token ReadOperator(char ch) Token ReadOperator(char ch)
{ {
int x = Col; int x = Col - 1;
int y = Line; int y = Line;
switch(ch) { switch(ch) {
case '+': case '+':

41
src/Libraries/NRefactory/Test/Lexer/CSharp/LexerPositionTests.cs

@ -78,15 +78,15 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken(); t = l.NextToken();
Assert.AreEqual(new Point(9, 1), t.Location); Assert.AreEqual(new Point(9, 1), t.Location);
} }
// [Test] [Test]
// public void TestFloationPointNumber() public void TestFloationPointNumber()
// { {
// ILexer l = GenerateLexer("0.142 public"); ILexer l = GenerateLexer("0.142 public");
// Token t = l.NextToken(); Token t = l.NextToken();
// Assert.AreEqual(new Point(1, 1), t.Location); Assert.AreEqual(new Point(1, 1), t.Location);
// t = l.NextToken(); t = l.NextToken();
// Assert.AreEqual(new Point(7, 1), t.Location); Assert.AreEqual(new Point(7, 1), t.Location);
// } }
[Test] [Test]
public void TestVerbatimString() public void TestVerbatimString()
{ {
@ -97,14 +97,23 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
Assert.AreEqual(new Point(9, 1), t.Location); Assert.AreEqual(new Point(9, 1), t.Location);
} }
[Test] [Test]
public void TestAtIdent()
{
ILexer l = GenerateLexer("@public =");
Token t = l.NextToken();
Assert.AreEqual(new Point(1, 1), t.Location);
t = l.NextToken();
Assert.AreEqual(new Point(9, 1), t.Location);
}
[Test]
public void TestNoFloationPointNumber() public void TestNoFloationPointNumber()
{ {
ILexer l = GenerateLexer("0.a"); ILexer l = GenerateLexer("5.a");
Token t = l.NextToken(); Token t = l.NextToken();
Console.WriteLine(t);
Assert.AreEqual(new Point(1, 1), t.Location); Assert.AreEqual(new Point(1, 1), t.Location);
t = l.NextToken(); t = l.NextToken();
Console.WriteLine(t); Assert.AreEqual(new Point(2, 1), t.Location);
t = l.NextToken();
Assert.AreEqual(new Point(3, 1), t.Location); Assert.AreEqual(new Point(3, 1), t.Location);
} }
[Test] [Test]
@ -123,5 +132,13 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.CSharp
t = l.NextToken(); t = l.NextToken();
Assert.AreEqual(new Point(4, 1), t.Location); Assert.AreEqual(new Point(4, 1), t.Location);
} }
[Test]
public void TestOperator()
{
ILexer l = GenerateLexer("<<=");
Token t = l.NextToken();
Assert.AreEqual(new Point(1, 1), t.Location);
Assert.AreEqual(Tokens.EOF, l.NextToken().kind);
}
} }
} }

14
src/Libraries/NRefactory/Test/Lexer/VBNet/LexerPositionTests.cs

@ -53,13 +53,13 @@ namespace ICSharpCode.NRefactory.Tests.Lexer.VB
Token t = l.NextToken(); Token t = l.NextToken();
Assert.AreEqual(new Point(3, 1), t.Location); Assert.AreEqual(new Point(3, 1), t.Location);
} }
// [Test] [Test]
// public void TestOctNumber() public void TestOctNumber()
// { {
// ILexer l = GenerateLexer("0142"); ILexer l = GenerateLexer("0142");
// Token t = l.NextToken(); Token t = l.NextToken();
// Assert.AreEqual(new Point(1, 1), t.Location); Assert.AreEqual(new Point(1, 1), t.Location);
// } }
// [Test] // [Test]
// public void TestHexNumber() // public void TestHexNumber()
// { // {

Loading…
Cancel
Save