Browse Source

C# lexer ready, begin with vb lexer.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@289 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Andrea Paatz 21 years ago
parent
commit
6a9debd3ad
  1. 4
      src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs
  2. 62
      src/Libraries/NRefactory/Project/Src/Lexer/CSharp/Lexer.cs
  3. 90
      src/Libraries/NRefactory/Project/Src/Lexer/VBNet/Lexer.cs
  4. 5
      src/Libraries/NRefactory/Test/Parser/GlobalScope/NamespaceDeclarationTests.cs

4
src/Libraries/NRefactory/Project/Src/Lexer/AbstractLexer.cs

@ -19,7 +19,6 @@ namespace ICSharpCode.NRefactory.Parser
public abstract class AbstractLexer : ILexer public abstract class AbstractLexer : ILexer
{ {
protected TextReader reader; protected TextReader reader;
protected int col = 1; protected int col = 1;
protected int line = 1; protected int line = 1;
@ -103,6 +102,7 @@ namespace ICSharpCode.NRefactory.Parser
/// </summary> /// </summary>
public Token Token { public Token Token {
get { get {
Console.WriteLine("Call to Token");
return lastToken; return lastToken;
} }
} }
@ -112,6 +112,7 @@ namespace ICSharpCode.NRefactory.Parser
/// </summary> /// </summary>
public Token LookAhead { public Token LookAhead {
get { get {
Console.WriteLine("Call to LookAhead");
return curToken; return curToken;
} }
} }
@ -151,6 +152,7 @@ namespace ICSharpCode.NRefactory.Parser
/// <returns>An <see cref="Token"/> object.</returns> /// <returns>An <see cref="Token"/> object.</returns>
public virtual Token Peek() public virtual Token Peek()
{ {
Console.WriteLine("Call to Peek");
if (peekToken.next == null) { if (peekToken.next == null) {
peekToken.next = Next(); peekToken.next = Next();
specialTracker.InformToken(peekToken.next.kind); specialTracker.InformToken(peekToken.next.kind);

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

@ -34,8 +34,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
} }
if (Char.IsLetter(ch) || ch == '_') { if (Char.IsLetter(ch) || ch == '_') {
int x = col - 1; // col was incremented above, but we want the start of the identifier int x = Col - 1; // Col was incremented above, but we want the start of the identifier
int y = line; int y = Line;
string s = ReadIdent(ch); string s = ReadIdent(ch);
int keyWordToken = Keywords.GetToken(s); int keyWordToken = Keywords.GetToken(s);
if (keyWordToken >= 0) { if (keyWordToken >= 0) {
@ -45,7 +45,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
} }
if (Char.IsDigit(ch)) { if (Char.IsDigit(ch)) {
return ReadDigit(ch, col - 1); return ReadDigit(ch, Col - 1);
} }
switch (ch) { switch (ch) {
@ -57,7 +57,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
} }
break; break;
case '#': case '#':
Point start = new Point(col - 1, line); Point start = new Point(Col - 1, Line);
string directive = ReadIdent('#'); string directive = ReadIdent('#');
string argument = ReadToEOL(); string argument = ReadToEOL();
this.specialTracker.AddPreProcessingDirective(directive, argument.Trim(), start, new Point(start.X + directive.Length + argument.Length, start.Y)); this.specialTracker.AddPreProcessingDirective(directive, argument.Trim(), start, new Point(start.X + directive.Length + argument.Length, start.Y));
@ -69,10 +69,10 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
case '@': case '@':
int next = ReaderRead(); int next = ReaderRead();
if (next == -1) { if (next == -1) {
errors.Error(line, col, String.Format("EOF after @")); errors.Error(Line, Col, String.Format("EOF after @"));
} else { } else {
int x = col; int x = Col;
int y = line; int y = Line;
ch = (char)next; ch = (char)next;
if (ch == '"') { if (ch == '"') {
return ReadVerbatimString(); return ReadVerbatimString();
@ -94,7 +94,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
return token; return token;
} }
return new Token(Tokens.EOF, col, line, String.Empty); return new Token(Tokens.EOF, Col, Line, String.Empty);
} }
// The C# compiler has a fixed size length therefore we'll use a fixed size char array for identifiers // The C# compiler has a fixed size length therefore we'll use a fixed size char array for identifiers
@ -113,7 +113,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
if (curPos < MAX_IDENTIFIER_LENGTH) { if (curPos < MAX_IDENTIFIER_LENGTH) {
identBuffer[curPos++] = ch; identBuffer[curPos++] = ch;
} else { } else {
errors.Error(line, col, String.Format("Identifier too long")); errors.Error(Line, Col, String.Format("Identifier too long"));
while ((peek = ReaderPeek()) != -1 && (Char.IsLetterOrDigit(ch = (char)peek) || ch == '_')) { while ((peek = ReaderPeek()) != -1 && (Char.IsLetterOrDigit(ch = (char)peek) || ch == '_')) {
ReaderRead(); ReaderRead();
} }
@ -126,7 +126,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadDigit(char ch, int x) Token ReadDigit(char ch, int x)
{ {
unchecked { // prevent exception when ReaderPeek() = -1 is cast to char unchecked { // prevent exception when ReaderPeek() = -1 is cast to char
int y = line; int y = Line;
sb.Length = 0; sb.Length = 0;
sb.Append(ch); sb.Append(ch);
string prefix = null; string prefix = null;
@ -319,8 +319,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadString() Token ReadString()
{ {
int x = col - 1; int x = Col - 1;
int y = line; int y = Line;
sb.Length = 0; sb.Length = 0;
originalValue.Length = 0; originalValue.Length = 0;
@ -358,8 +358,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadVerbatimString() Token ReadVerbatimString()
{ {
int x = col; int x = Col;
int y = line; int y = Line;
int nextChar; int nextChar;
sb.Length = 0; sb.Length = 0;
originalValue.Length = 0; originalValue.Length = 0;
@ -397,7 +397,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
{ {
int nextChar = ReaderRead(); int nextChar = ReaderRead();
if (nextChar == -1) { if (nextChar == -1) {
errors.Error(line, col, String.Format("End of file reached inside escape sequence")); errors.Error(Line, Col, String.Format("End of file reached inside escape sequence"));
ch = '\0'; ch = '\0';
return String.Empty; return String.Empty;
} }
@ -445,7 +445,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
escapeSequenceBuffer[curPos++] = c; escapeSequenceBuffer[curPos++] = c;
if (number < 0) { if (number < 0) {
errors.Error(line, col - 1, String.Format("Invalid char in literal : {0}", c)); errors.Error(Line, Col - 1, String.Format("Invalid char in literal : {0}", c));
} }
for (int i = 0; i < 3; ++i) { for (int i = 0; i < 3; ++i) {
if (IsHex((char)ReaderPeek())) { if (IsHex((char)ReaderPeek())) {
@ -460,7 +460,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
ch = (char)number; ch = (char)number;
break; break;
default: default:
errors.Error(line, col, String.Format("Unexpected escape sequence : {0}", c)); errors.Error(Line, Col, String.Format("Unexpected escape sequence : {0}", c));
ch = '\0'; ch = '\0';
break; break;
} }
@ -469,8 +469,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadChar() Token ReadChar()
{ {
int x = col - 1; int x = Col - 1;
int y = line; int y = Line;
int nextChar = ReaderRead(); int nextChar = ReaderRead();
if (nextChar == -1) { if (nextChar == -1) {
errors.Error(y, x, String.Format("End of file reached inside character literal")); errors.Error(y, x, String.Format("End of file reached inside character literal"));
@ -493,8 +493,8 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
Token ReadOperator(char ch) Token ReadOperator(char ch)
{ {
int x = col; int x = Col;
int y = line; int y = Line;
switch (ch) { switch (ch) {
case '+': case '+':
switch (ReaderPeek()) { switch (ReaderPeek()) {
@ -640,7 +640,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
// Prevent OverflowException when ReaderPeek returns -1 // Prevent OverflowException when ReaderPeek returns -1
int tmp = ReaderPeek(); int tmp = ReaderPeek();
if (tmp > 0 && Char.IsDigit((char)tmp)) { if (tmp > 0 && Char.IsDigit((char)tmp)) {
return ReadDigit('.', col - 1); return ReadDigit('.', Col - 1);
} }
return new Token(Tokens.Dot, x, y); return new Token(Tokens.Dot, x, y);
case ')': case ')':
@ -675,7 +675,7 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
} }
break; break;
default: default:
errors.Error(line, col, String.Format("Error while reading comment")); errors.Error(Line, Col, String.Format("Error while reading comment"));
break; break;
} }
} }
@ -701,9 +701,9 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
string tag = curWord.ToString(); string tag = curWord.ToString();
curWord.Length = 0; curWord.Length = 0;
if (specialCommentHash.ContainsKey(tag)) { if (specialCommentHash.ContainsKey(tag)) {
Point p = new Point(col, line); Point p = new Point(Col, Line);
string comment = ReadToEOL(); string comment = ReadToEOL();
tagComments.Add(new TagComment(tag, comment, p, new Point(col, line))); tagComments.Add(new TagComment(tag, comment, p, new Point(Col, Line)));
sb.Append(comment); sb.Append(comment);
break; break;
} }
@ -715,14 +715,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
void ReadSingleLineComment(CommentType commentType) void ReadSingleLineComment(CommentType commentType)
{ {
specialTracker.StartComment(commentType, new Point(col, line)); specialTracker.StartComment(commentType, new Point(Col, Line));
specialTracker.AddString(ReadCommentToEOL()); specialTracker.AddString(ReadCommentToEOL());
specialTracker.FinishComment(new Point(col, line)); specialTracker.FinishComment(new Point(Col, Line));
} }
void ReadMultiLineComment() void ReadMultiLineComment()
{ {
specialTracker.StartComment(CommentType.Block, new Point(col, line)); specialTracker.StartComment(CommentType.Block, new Point(Col, Line));
int nextChar; int nextChar;
while ((nextChar = ReaderRead()) != -1) { while ((nextChar = ReaderRead()) != -1) {
char ch = (char)nextChar; char ch = (char)nextChar;
@ -735,14 +735,14 @@ namespace ICSharpCode.NRefactory.Parser.CSharp
// End of multiline comment reached ? // End of multiline comment reached ?
if (ch == '*' && ReaderPeek() == '/') { if (ch == '*' && ReaderPeek() == '/') {
ReaderRead(); ReaderRead();
specialTracker.FinishComment(new Point(col, line)); specialTracker.FinishComment(new Point(Col, Line));
return; return;
} }
specialTracker.AddChar(ch); specialTracker.AddChar(ch);
} }
specialTracker.FinishComment(new Point(col, line)); specialTracker.FinishComment(new Point(Col, Line));
// Reached EOF before end of multiline comment. // Reached EOF before end of multiline comment.
errors.Error(line, col, String.Format("Reached EOF before the end of a multiline comment")); errors.Error(Line, Col, String.Format("Reached EOF before the end of a multiline comment"));
} }
/// <summary> /// <summary>

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

@ -65,7 +65,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
int y = line; int y = line;
++line; ++line;
col = 1; col = 1;
if (reader.Peek() == '\r') { if (ReaderPeek() == '\r') {
reader.Read(); reader.Read();
if (!lineEnd) { if (!lineEnd) {
lineEnd = true; lineEnd = true;
@ -81,12 +81,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
if (ch == '_') { if (ch == '_') {
if (reader.Peek() == -1) { if (ReaderPeek() == -1) {
errors.Error(line, col, String.Format("No EOF expected after _")); errors.Error(line, col, String.Format("No EOF expected after _"));
return new Token(Tokens.EOF); return new Token(Tokens.EOF);
} }
++col; ++col;
if (!Char.IsWhiteSpace((char)reader.Peek())) { if (!Char.IsWhiteSpace((char)ReaderPeek())) {
--col; --col;
int x = col; int x = col;
int y = line; int y = line;
@ -103,7 +103,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
col = 1; col = 1;
break; break;
} }
if (reader.Peek() != -1) { if (ReaderPeek() != -1) {
ch = (char)reader.Read(); ch = (char)reader.Read();
++col; ++col;
} }
@ -115,11 +115,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
if (ch == '#') { if (ch == '#') {
while (Char.IsWhiteSpace((char)reader.Peek())) { while (Char.IsWhiteSpace((char)ReaderPeek())) {
++col; ++col;
reader.Read(); reader.Read();
} }
if (Char.IsDigit((char)reader.Peek())) { if (Char.IsDigit((char)ReaderPeek())) {
int x = col; int x = col;
int y = line; int y = line;
string s = ReadDate(); string s = ReadDate();
@ -138,7 +138,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if (ch == '[') { // Identifier if (ch == '[') { // Identifier
lineEnd = false; lineEnd = false;
if (reader.Peek() == -1) { if (ReaderPeek() == -1) {
errors.Error(line, col, String.Format("Identifier expected")); errors.Error(line, col, String.Format("Identifier expected"));
} }
ch = (char)reader.Read(); ch = (char)reader.Read();
@ -149,7 +149,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
int x = col - 1; int x = col - 1;
int y = line; int y = line;
string s = ReadIdent(ch); string s = ReadIdent(ch);
if (reader.Peek() == -1) { if (ReaderPeek() == -1) {
errors.Error(line, col, String.Format("']' expected")); errors.Error(line, col, String.Format("']' expected"));
} }
ch = (char)reader.Read(); ch = (char)reader.Read();
@ -189,10 +189,10 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
if (ch == '&') { if (ch == '&') {
lineEnd = false; lineEnd = false;
if (reader.Peek() == -1) { if (ReaderPeek() == -1) {
return ReadOperator('&'); return ReadOperator('&');
} }
ch = (char)reader.Peek(); ch = (char)ReaderPeek();
++col; ++col;
if (Char.ToUpper(ch) == 'H' || Char.ToUpper(ch) == 'O') { if (Char.ToUpper(ch) == 'H' || Char.ToUpper(ch) == 'O') {
--col; --col;
@ -215,7 +215,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
int x = col - 1; int x = col - 1;
int y = line; int y = line;
string s = ReadString(); string s = ReadString();
if (reader.Peek() != -1 && (reader.Peek() == 'C' || reader.Peek() == 'c')) { if (ReaderPeek() != -1 && (ReaderPeek() == 'C' || ReaderPeek() == 'c')) {
reader.Read(); reader.Read();
++col; ++col;
if (s.Length != 1) { if (s.Length != 1) {
@ -241,7 +241,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
sb.Length = 0; sb.Length = 0;
sb.Append(ch); sb.Append(ch);
int peek; int peek;
while ((peek = reader.Peek()) != -1 && (Char.IsLetterOrDigit(ch = (char)peek) || ch == '_')) { while ((peek = ReaderPeek()) != -1 && (Char.IsLetterOrDigit(ch = (char)peek) || ch == '_')) {
reader.Read(); reader.Read();
++col; ++col;
sb.Append(ch.ToString()); sb.Append(ch.ToString());
@ -277,40 +277,40 @@ namespace ICSharpCode.NRefactory.Parser.VB
bool isdouble = false; bool isdouble = false;
bool isdecimal = false; bool isdecimal = false;
if (reader.Peek() == -1) { if (ReaderPeek() == -1) {
if (ch == '&') { if (ch == '&') {
errors.Error(line, col, String.Format("digit expected")); errors.Error(line, col, String.Format("digit expected"));
} }
return new Token(Tokens.LiteralInteger, x, y, sb.ToString() ,ch - '0'); return new Token(Tokens.LiteralInteger, x, y, sb.ToString() ,ch - '0');
} }
if (ch == '.') { if (ch == '.') {
if (Char.IsDigit((char)reader.Peek())) { if (Char.IsDigit((char)ReaderPeek())) {
isdouble = true; // double is default isdouble = true; // double is default
if (ishex || isokt) { if (ishex || isokt) {
errors.Error(line, col, String.Format("No hexadecimal or oktadecimal floating point values allowed")); errors.Error(line, col, String.Format("No hexadecimal or oktadecimal floating point values allowed"));
} }
++col; ++col;
while (reader.Peek() != -1 && Char.IsDigit((char)reader.Peek())){ // read decimal digits beyond the dot while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())){ // read decimal digits beyond the dot
digit += (char)reader.Read(); digit += (char)reader.Read();
++col; ++col;
} }
} }
} else if (ch == '&' && Char.ToUpper((char)reader.Peek()) == 'H') { } else if (ch == '&' && Char.ToUpper((char)ReaderPeek()) == 'H') {
const string hex = "0123456789ABCDEF"; const string hex = "0123456789ABCDEF";
sb.Append((char)reader.Read()); // skip 'H' sb.Append((char)reader.Read()); // skip 'H'
++col; ++col;
while (reader.Peek() != -1 && hex.IndexOf(Char.ToUpper((char)reader.Peek())) != -1) { while (ReaderPeek() != -1 && hex.IndexOf(Char.ToUpper((char)ReaderPeek())) != -1) {
ch = (char)reader.Read(); ch = (char)reader.Read();
sb.Append(ch); sb.Append(ch);
digit += Char.ToUpper(ch); digit += Char.ToUpper(ch);
++col; ++col;
} }
ishex = true; ishex = true;
} else if (reader.Peek() != -1 && ch == '&' && Char.ToUpper((char)reader.Peek()) == 'O') { } else if (ReaderPeek() != -1 && ch == '&' && Char.ToUpper((char)ReaderPeek()) == 'O') {
const string okt = "01234567"; const string okt = "01234567";
sb.Append((char)reader.Read()); // skip 'O' sb.Append((char)reader.Read()); // skip 'O'
++col; ++col;
while (reader.Peek() != -1 && okt.IndexOf(Char.ToUpper((char)reader.Peek())) != -1) { while (ReaderPeek() != -1 && okt.IndexOf(Char.ToUpper((char)ReaderPeek())) != -1) {
ch = (char)reader.Read(); ch = (char)reader.Read();
sb.Append(ch); sb.Append(ch);
digit += Char.ToUpper(ch); digit += Char.ToUpper(ch);
@ -318,7 +318,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
isokt = true; isokt = true;
} else { } else {
while (reader.Peek() != -1 && Char.IsDigit((char)reader.Peek())) { while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) {
ch = (char)reader.Read();; ch = (char)reader.Read();;
digit += ch; digit += ch;
sb.Append(ch); sb.Append(ch);
@ -326,13 +326,13 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
} }
if (reader.Peek() != -1 && ("%&SILU".IndexOf(Char.ToUpper((char)reader.Peek())) != -1 || ishex || isokt)) { if (ReaderPeek() != -1 && ("%&SILU".IndexOf(Char.ToUpper((char)ReaderPeek())) != -1 || ishex || isokt)) {
ch = (char)reader.Peek(); ch = (char)ReaderPeek();
sb.Append(ch); sb.Append(ch);
ch = Char.ToUpper(ch); ch = Char.ToUpper(ch);
bool unsigned = ch == 'U'; bool unsigned = ch == 'U';
if (unsigned) { if (unsigned) {
ch = (char)reader.Peek(); ch = (char)ReaderPeek();
sb.Append(ch); sb.Append(ch);
ch = Char.ToUpper(ch); ch = Char.ToUpper(ch);
if (ch != 'I' && ch != 'L' && ch != 'S') { if (ch != 'I' && ch != 'L' && ch != 'S') {
@ -398,16 +398,16 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
} }
Token nextToken = null; // if we accedently read a 'dot' Token nextToken = null; // if we accedently read a 'dot'
if (!isdouble && reader.Peek() == '.') { // read floating point number if (!isdouble && ReaderPeek() == '.') { // read floating point number
reader.Read(); reader.Read();
if (reader.Peek() != -1 && Char.IsDigit((char)reader.Peek())) { if (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) {
isdouble = true; // double is default isdouble = true; // double is default
if (ishex || isokt) { if (ishex || isokt) {
errors.Error(line, col, String.Format("No hexadecimal or oktadecimal floating point values allowed")); errors.Error(line, col, String.Format("No hexadecimal or oktadecimal floating point values allowed"));
} }
digit += '.'; digit += '.';
++col; ++col;
while (reader.Peek() != -1 && Char.IsDigit((char)reader.Peek())){ // read decimal digits beyond the dot while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())){ // read decimal digits beyond the dot
digit += (char)reader.Read(); digit += (char)reader.Read();
++col; ++col;
} }
@ -416,22 +416,22 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
} }
if (reader.Peek() != -1 && Char.ToUpper((char)reader.Peek()) == 'E') { // read exponent if (ReaderPeek() != -1 && Char.ToUpper((char)ReaderPeek()) == 'E') { // read exponent
isdouble = true; isdouble = true;
digit += (char)reader.Read(); digit += (char)reader.Read();
++col; ++col;
if (reader.Peek() != -1 && (reader.Peek() == '-' || reader.Peek() == '+')) { if (ReaderPeek() != -1 && (ReaderPeek() == '-' || ReaderPeek() == '+')) {
digit += (char)reader.Read(); digit += (char)reader.Read();
++col; ++col;
} }
while (reader.Peek() != -1 && Char.IsDigit((char)reader.Peek())) { // read exponent value while (ReaderPeek() != -1 && Char.IsDigit((char)ReaderPeek())) { // read exponent value
digit += (char)reader.Read(); digit += (char)reader.Read();
++col; ++col;
} }
} }
if (reader.Peek() != -1) { if (ReaderPeek() != -1) {
switch (char.ToUpper((char)reader.Peek())) { switch (char.ToUpper((char)ReaderPeek())) {
case 'R': case 'R':
case '#': case '#':
reader.Read(); reader.Read();
@ -531,7 +531,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
ch = (char)nextChar; ch = (char)nextChar;
++col; ++col;
if (ch == '"') { if (ch == '"') {
if (reader.Peek() != -1 && reader.Peek() == '"') { if (ReaderPeek() != -1 && ReaderPeek() == '"') {
sb.Append('"'); sb.Append('"');
reader.Read(); reader.Read();
++col; ++col;
@ -610,7 +610,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
int y = line; int y = line;
switch(ch) { switch(ch) {
case '+': case '+':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -620,7 +620,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.Plus, x, y); return new Token(Tokens.Plus, x, y);
case '-': case '-':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -630,7 +630,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.Minus, x, y); return new Token(Tokens.Minus, x, y);
case '*': case '*':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -640,7 +640,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.Times, x, y, "*"); return new Token(Tokens.Times, x, y, "*");
case '/': case '/':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -650,7 +650,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.Div, x, y); return new Token(Tokens.Div, x, y);
case '\\': case '\\':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -660,7 +660,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.DivInteger, x, y); return new Token(Tokens.DivInteger, x, y);
case '&': case '&':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -670,7 +670,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.ConcatString, x, y); return new Token(Tokens.ConcatString, x, y);
case '^': case '^':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -684,7 +684,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '=': case '=':
return new Token(Tokens.Assign, x, y); return new Token(Tokens.Assign, x, y);
case '<': case '<':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
@ -695,7 +695,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
return new Token(Tokens.NotEqual, x, y); return new Token(Tokens.NotEqual, x, y);
case '<': case '<':
reader.Read(); reader.Read();
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
col += 2; col += 2;
@ -708,15 +708,15 @@ namespace ICSharpCode.NRefactory.Parser.VB
} }
return new Token(Tokens.LessThan, x, y); return new Token(Tokens.LessThan, x, y);
case '>': case '>':
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
++col; ++col;
return new Token(Tokens.GreaterEqual, x, y); return new Token(Tokens.GreaterEqual, x, y);
case '>': case '>':
reader.Read(); reader.Read();
if (reader.Peek() != -1) { if (ReaderPeek() != -1) {
switch (reader.Peek()) { switch (ReaderPeek()) {
case '=': case '=':
reader.Read(); reader.Read();
col += 2; col += 2;
@ -733,7 +733,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
return new Token(Tokens.Comma, x, y); return new Token(Tokens.Comma, x, y);
case '.': case '.':
// Prevent OverflowException when Peek returns -1 // Prevent OverflowException when Peek returns -1
int tmp = reader.Peek(); int tmp = ReaderPeek();
if (tmp > 0 && Char.IsDigit((char)tmp)) { if (tmp > 0 && Char.IsDigit((char)tmp)) {
--col; --col;
return ReadDigit('.', col); return ReadDigit('.', col);

5
src/Libraries/NRefactory/Test/Parser/GlobalScope/NamespaceDeclarationTests.cs

@ -53,9 +53,8 @@ namespace ICSharpCode.NRefactory.Tests.AST
[Test] [Test]
public void VBNetSimpleNamespaceTest() public void VBNetSimpleNamespaceTest()
{ {
string program = "Namespace TestNamespace\n" + string program = "Namespace TestNamespace" + Environment.NewLine +
"End Namespace\n"; "End Namespace" +Environment.NewLine;
NamespaceDeclaration ns = (NamespaceDeclaration)ParseUtilVBNet.ParseGlobal(program, typeof(NamespaceDeclaration)); NamespaceDeclaration ns = (NamespaceDeclaration)ParseUtilVBNet.ParseGlobal(program, typeof(NamespaceDeclaration));
Assert.AreEqual("TestNamespace", ns.Name); Assert.AreEqual("TestNamespace", ns.Name);
} }

Loading…
Cancel
Save