@ -55,79 +55,63 @@ namespace ICSharpCode.NRefactory.Parser.VB
protected override Token Next ( )
protected override Token Next ( )
{
{
int nextChar ;
int nextChar ;
while ( ( nextChar = reader . Read ( ) ) ! = - 1 ) {
while ( ( nextChar = Reader Read( ) ) ! = - 1 ) {
char ch = ( char ) nextChar ;
char ch = ( char ) nextChar ;
+ + col ;
if ( Char . IsWhiteSpace ( ch ) ) {
if ( Char . IsWhiteSpace ( ch ) ) {
if ( ch = = '\n' ) {
int x = Col ;
int x = col - 1 ;
int y = Line ;
int y = line ;
if ( HandleLineEnd ( ch ) ) {
+ + line ;
col = 1 ;
if ( ReaderPeek ( ) = = '\r' ) {
reader . Read ( ) ;
if ( ! lineEnd ) {
lineEnd = true ;
return new Token ( Tokens . EOL , x - 1 , y , "\n\r" ) ;
}
}
if ( ! lineEnd ) {
if ( ! lineEnd ) {
lineEnd = true ;
lineEnd = true ;
return new Token ( Tokens . EOL , x , y , "\n" ) ;
return new Token ( Tokens . EOL , x , y ) ;
}
}
}
}
continue ;
continue ;
}
}
if ( ch = = '_' ) {
if ( ch = = '_' ) {
if ( ReaderPeek ( ) = = - 1 ) {
if ( ReaderPeek ( ) = = - 1 ) {
errors . Error ( line , c ol, String . Format ( "No EOF expected after _" ) ) ;
errors . Error ( Line , C ol, String . Format ( "No EOF expected after _" ) ) ;
return new Token ( Tokens . EOF ) ;
return new Token ( Tokens . EOF ) ;
}
}
+ + col ;
if ( ! Char . IsWhiteSpace ( ( char ) ReaderPeek ( ) ) ) {
if ( ! Char . IsWhiteSpace ( ( char ) ReaderPeek ( ) ) ) {
- - col ;
int x = Col ;
int x = col ;
int y = Line ;
int y = line ;
string s = ReadIdent ( '_' ) ;
string s = ReadIdent ( '_' ) ;
lineEnd = false ;
lineEnd = false ;
return new Token ( Tokens . Identifier , x , y , s ) ;
return new Token ( Tokens . Identifier , x , y , s ) ;
}
}
ch = ( char ) reader . Read ( ) ;
ch = ( char ) Reader Read( ) ;
lineEnd = false ;
while ( Char . IsWhiteSpace ( ch ) ) {
while ( Char . IsWhiteSpace ( ch ) ) {
if ( ch = = '\n' ) {
if ( HandleLineEnd ( ch ) ) {
+ + line ;
lineEnd = true ;
col = 1 ;
break ;
break ;
}
}
if ( ReaderPeek ( ) ! = - 1 ) {
if ( ReaderPeek ( ) ! = - 1 ) {
ch = ( char ) reader . Read ( ) ;
ch = ( char ) ReaderRead ( ) ;
+ + col ;
}
}
}
}
if ( ch ! = '\n' ) {
if ( ! lineEnd ) {
errors . Error ( line , c ol, String . Format ( "Return expected" ) ) ;
errors . Error ( Line , C ol, String . Format ( "Return expected" ) ) ;
}
}
lineEnd = false ;
continue ;
continue ;
}
}
if ( ch = = '#' ) {
if ( ch = = '#' ) {
while ( Char . IsWhiteSpace ( ( char ) ReaderPeek ( ) ) ) {
while ( Char . IsWhiteSpace ( ( char ) ReaderPeek ( ) ) ) {
+ + col ;
ReaderRead ( ) ;
reader . Read ( ) ;
}
}
if ( Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
if ( Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
int x = c ol;
int x = C ol;
int y = l ine;
int y = L ine;
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 ) ;
try {
try {
time = DateTime . Parse ( s , System . Globalization . CultureInfo . InvariantCulture , DateTimeStyles . NoCurrentDateDefault ) ;
time = DateTime . Parse ( s , System . Globalization . CultureInfo . InvariantCulture , DateTimeStyles . NoCurrentDateDefault ) ;
} catch ( Exception e ) {
} catch ( Exception e ) {
errors . Error ( line , c ol, String . Format ( "Invalid date time {0}" , e ) ) ;
errors . Error ( Line , C ol, String . Format ( "Invalid date time {0}" , e ) ) ;
}
}
return new Token ( Tokens . LiteralDate , x , y , s , time ) ;
return new Token ( Tokens . LiteralDate , x , y , s , time ) ;
} else {
} else {
@ -139,29 +123,27 @@ namespace ICSharpCode.NRefactory.Parser.VB
if ( ch = = '[' ) { // Identifier
if ( ch = = '[' ) { // Identifier
lineEnd = false ;
lineEnd = false ;
if ( ReaderPeek ( ) = = - 1 ) {
if ( ReaderPeek ( ) = = - 1 ) {
errors . Error ( line , c ol, String . Format ( "Identifier expected" ) ) ;
errors . Error ( Line , C ol, String . Format ( "Identifier expected" ) ) ;
}
}
ch = ( char ) reader . Read ( ) ;
ch = ( char ) ReaderRead ( ) ;
+ + col ;
if ( ch = = ']' | | Char . IsWhiteSpace ( ch ) ) {
if ( ch = = ']' | | Char . IsWhiteSpace ( ch ) ) {
errors . Error ( line , c ol, String . Format ( "Identifier expected" ) ) ;
errors . Error ( Line , C ol, String . Format ( "Identifier expected" ) ) ;
}
}
int x = c ol - 1 ;
int x = C ol - 1 ;
int y = l ine;
int y = L ine;
string s = ReadIdent ( ch ) ;
string s = ReadIdent ( ch ) ;
if ( ReaderPeek ( ) = = - 1 ) {
if ( ReaderPeek ( ) = = - 1 ) {
errors . Error ( line , c ol, String . Format ( "']' expected" ) ) ;
errors . Error ( Line , C ol, String . Format ( "']' expected" ) ) ;
}
}
ch = ( char ) reader . Read ( ) ;
ch = ( char ) ReaderRead ( ) ;
+ + col ;
if ( ! ( ch = = ']' ) ) {
if ( ! ( ch = = ']' ) ) {
errors . Error ( line , c ol, String . Format ( "']' expected" ) ) ;
errors . Error ( Line , C ol, String . Format ( "']' expected" ) ) ;
}
}
return new Token ( Tokens . Identifier , x , y , s ) ;
return new Token ( Tokens . Identifier , x , y , s ) ;
}
}
if ( Char . IsLetter ( ch ) ) {
if ( Char . IsLetter ( ch ) ) {
int x = c ol - 1 ;
int x = C ol - 1 ;
int y = l ine;
int y = L ine;
string s = ReadIdent ( ch ) ;
string s = ReadIdent ( ch ) ;
int keyWordToken = Keywords . GetToken ( s ) ;
int keyWordToken = Keywords . GetToken ( s ) ;
if ( keyWordToken > = 0 ) {
if ( keyWordToken > = 0 ) {
@ -185,7 +167,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
}
if ( Char . IsDigit ( ch ) ) {
if ( Char . IsDigit ( ch ) ) {
lineEnd = false ;
lineEnd = false ;
return ReadDigit ( ch , c ol) ;
return ReadDigit ( ch , C ol) ;
}
}
if ( ch = = '&' ) {
if ( ch = = '&' ) {
lineEnd = false ;
lineEnd = false ;
@ -193,16 +175,14 @@ namespace ICSharpCode.NRefactory.Parser.VB
return ReadOperator ( '&' ) ;
return ReadOperator ( '&' ) ;
}
}
ch = ( char ) ReaderPeek ( ) ;
ch = ( char ) ReaderPeek ( ) ;
+ + col ;
if ( Char . ToUpper ( ch ) = = 'H' | | Char . ToUpper ( ch ) = = 'O' ) {
if ( Char . ToUpper ( ch ) = = 'H' | | Char . ToUpper ( ch ) = = 'O' ) {
- - col ;
return ReadDigit ( '&' , Col ) ;
return ReadDigit ( '&' , col ) ;
}
}
return ReadOperator ( '&' ) ;
return ReadOperator ( '&' ) ;
}
}
if ( ch = = '\'' | | ch = = ' \ u2018 ' | | ch = = ' \ u2019 ' ) {
if ( ch = = '\'' | | ch = = ' \ u2018 ' | | ch = = ' \ u2019 ' ) {
int x = c ol - 1 ;
int x = C ol - 1 ;
int y = l ine;
int y = L ine;
ReadComment ( ) ;
ReadComment ( ) ;
if ( ! lineEnd ) {
if ( ! lineEnd ) {
lineEnd = true ;
lineEnd = true ;
@ -212,14 +192,13 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
}
if ( ch = = '"' ) {
if ( ch = = '"' ) {
lineEnd = false ;
lineEnd = false ;
int x = c ol - 1 ;
int x = C ol - 1 ;
int y = l ine;
int y = L ine;
string s = ReadString ( ) ;
string s = ReadString ( ) ;
if ( ReaderPeek ( ) ! = - 1 & & ( ReaderPeek ( ) = = 'C' | | ReaderPeek ( ) = = 'c' ) ) {
if ( ReaderPeek ( ) ! = - 1 & & ( ReaderPeek ( ) = = 'C' | | ReaderPeek ( ) = = 'c' ) ) {
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
if ( s . Length ! = 1 ) {
if ( s . Length ! = 1 ) {
errors . Error ( line , c ol, String . Format ( "Chars can only have Length 1 " ) ) ;
errors . Error ( Line , C ol, String . Format ( "Chars can only have Length 1 " ) ) ;
}
}
return new Token ( Tokens . LiteralCharacter , x , y , '"' + s + "\"C" , s [ 0 ] ) ;
return new Token ( Tokens . LiteralCharacter , x , y , '"' + s + "\"C" , s [ 0 ] ) ;
}
}
@ -230,7 +209,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
lineEnd = false ;
lineEnd = false ;
return token ;
return token ;
}
}
errors . Error ( line , c ol, String . Format ( "Unknown char({0}) which can't be read" , ch ) ) ;
errors . Error ( Line , C ol, String . Format ( "Unknown char({0}) which can't be read" , ch ) ) ;
}
}
return new Token ( Tokens . EOF ) ;
return new Token ( Tokens . EOF ) ;
@ -242,20 +221,15 @@ namespace ICSharpCode.NRefactory.Parser.VB
sb . Append ( ch ) ;
sb . Append ( ch ) ;
int peek ;
int peek ;
while ( ( peek = ReaderPeek ( ) ) ! = - 1 & & ( Char . IsLetterOrDigit ( ch = ( char ) peek ) | | ch = = '_' ) ) {
while ( ( peek = ReaderPeek ( ) ) ! = - 1 & & ( Char . IsLetterOrDigit ( ch = ( char ) peek ) | | ch = = '_' ) ) {
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
sb . Append ( ch . ToString ( ) ) ;
sb . Append ( ch . ToString ( ) ) ;
}
}
+ + col ;
if ( peek = = - 1 ) {
if ( peek = = - 1 ) {
- - col ;
return sb . ToString ( ) ;
return sb . ToString ( ) ;
}
}
- - col ;
if ( peek ! = - 1 & & "%&@!#$" . IndexOf ( ( char ) peek ) ! = - 1 ) {
if ( peek ! = - 1 & & "%&@!#$" . IndexOf ( ( char ) peek ) ! = - 1 ) {
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
}
}
return sb . ToString ( ) ;
return sb . ToString ( ) ;
}
}
@ -265,7 +239,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
sb . Length = 0 ;
sb . Length = 0 ;
sb . Append ( ch ) ;
sb . Append ( ch ) ;
int y = l ine;
int y = L ine;
string digit = "" ;
string digit = "" ;
if ( ch ! = '&' ) {
if ( ch ! = '&' ) {
digit + = ch ;
digit + = ch ;
@ -279,7 +253,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
if ( ReaderPeek ( ) = = - 1 ) {
if ( ReaderPeek ( ) = = - 1 ) {
if ( ch = = '&' ) {
if ( ch = = '&' ) {
errors . Error ( line , c ol, String . Format ( "digit expected" ) ) ;
errors . Error ( Line , C ol, 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' ) ;
}
}
@ -287,42 +261,35 @@ namespace ICSharpCode.NRefactory.Parser.VB
if ( Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
if ( Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
isdouble = true ; // double is default
isdouble = true ; // double is default
if ( ishex | | isokt ) {
if ( ishex | | isokt ) {
errors . Error ( line , c ol, String . Format ( "No hexadecimal or oktadecimal floating point values allowed" ) ) ;
errors . Error ( Line , C ol, String . Format ( "No hexadecimal or oktadecimal floating point values allowed" ) ) ;
}
}
+ + col ;
while ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) { // 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 ) ReaderRead ( ) ;
+ + col ;
}
}
}
}
} else if ( ch = = '&' & & Char . ToUpper ( ( char ) ReaderPeek ( ) ) = = '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 ) ReaderRead ( ) ) ; // skip 'H'
+ + col ;
while ( ReaderPeek ( ) ! = - 1 & & hex . IndexOf ( Char . ToUpper ( ( char ) ReaderPeek ( ) ) ) ! = - 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 ;
}
}
ishex = true ;
ishex = true ;
} else if ( ReaderPeek ( ) ! = - 1 & & ch = = '&' & & Char . ToUpper ( ( char ) ReaderPeek ( ) ) = = '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 ) ReaderRead ( ) ) ; // skip 'O'
+ + col ;
while ( ReaderPeek ( ) ! = - 1 & & okt . IndexOf ( Char . ToUpper ( ( char ) ReaderPeek ( ) ) ) ! = - 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 ) ;
+ + col ;
}
}
isokt = true ;
isokt = true ;
} else {
} else {
while ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
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 ) ;
+ + col ;
}
}
}
}
@ -336,12 +303,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
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' ) {
errors . Error ( line , c ol, "Invalid type character: U" + ch ) ;
errors . Error ( Line , C ol, "Invalid type character: U" + ch ) ;
}
}
}
}
+ + col ;
if ( isokt ) {
if ( isokt ) {
reader . Read ( ) ;
Reader Read( ) ;
ulong number = 0L ;
ulong number = 0L ;
for ( int i = 0 ; i < digit . Length ; + + i ) {
for ( int i = 0 ; i < digit . Length ; + + i ) {
number = number * 8 + digit [ i ] - '0' ;
number = number * 8 + digit [ i ] - '0' ;
@ -370,25 +336,24 @@ namespace ICSharpCode.NRefactory.Parser.VB
}
}
}
}
if ( ch = = 'S' ) {
if ( ch = = 'S' ) {
reader . Read ( ) ;
Reader Read( ) ;
if ( unsigned )
if ( unsigned )
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt16 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt16 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
else
else
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int16 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int16 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
} else if ( ch = = '%' | | ch = = 'I' ) {
} else if ( ch = = '%' | | ch = = 'I' ) {
reader . Read ( ) ;
Reader Read( ) ;
if ( unsigned )
if ( unsigned )
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt32 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt32 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
else
else
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int32 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int32 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
} else if ( ch = = '&' | | ch = = 'L' ) {
} else if ( ch = = '&' | | ch = = 'L' ) {
reader . Read ( ) ;
Reader Read( ) ;
if ( unsigned )
if ( unsigned )
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , UInt64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
else
else
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
} else if ( ishex ) {
} else if ( ishex ) {
- - col ;
ulong number = UInt64 . Parse ( digit , NumberStyles . HexNumber ) ;
ulong number = UInt64 . Parse ( digit , NumberStyles . HexNumber ) ;
if ( number > uint . MaxValue ) {
if ( number > uint . MaxValue ) {
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , unchecked ( ( long ) number ) ) ;
return new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , unchecked ( ( long ) number ) ) ;
@ -399,17 +364,15 @@ 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 & & ReaderPeek ( ) = = '.' ) { // read floating point number
if ( ! isdouble & & ReaderPeek ( ) = = '.' ) { // read floating point number
reader . Read ( ) ;
Reader Read( ) ;
if ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) {
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 , c ol, String . Format ( "No hexadecimal or oktadecimal floating point values allowed" ) ) ;
errors . Error ( Line , C ol, String . Format ( "No hexadecimal or oktadecimal floating point values allowed" ) ) ;
}
}
digit + = '.' ;
digit + = '.' ;
+ + col ;
while ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) { // 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 ) ReaderRead ( ) ;
+ + col ;
}
}
} else {
} else {
nextToken = new Token ( Tokens . Dot , x , y ) ;
nextToken = new Token ( Tokens . Dot , x , y ) ;
@ -418,15 +381,12 @@ namespace ICSharpCode.NRefactory.Parser.VB
if ( ReaderPeek ( ) ! = - 1 & & Char . ToUpper ( ( char ) ReaderPeek ( ) ) = = 'E' ) { // read exponent
if ( ReaderPeek ( ) ! = - 1 & & Char . ToUpper ( ( char ) ReaderPeek ( ) ) = = 'E' ) { // read exponent
isdouble = true ;
isdouble = true ;
digit + = ( char ) reader . Read ( ) ;
digit + = ( char ) ReaderRead ( ) ;
+ + col ;
if ( ReaderPeek ( ) ! = - 1 & & ( ReaderPeek ( ) = = '-' | | ReaderPeek ( ) = = '+' ) ) {
if ( ReaderPeek ( ) ! = - 1 & & ( ReaderPeek ( ) = = '-' | | ReaderPeek ( ) = = '+' ) ) {
digit + = ( char ) reader . Read ( ) ;
digit + = ( char ) ReaderRead ( ) ;
+ + col ;
}
}
while ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) { // read exponent value
while ( ReaderPeek ( ) ! = - 1 & & Char . IsDigit ( ( char ) ReaderPeek ( ) ) ) { // read exponent value
digit + = ( char ) reader . Read ( ) ;
digit + = ( char ) ReaderRead ( ) ;
+ + col ;
}
}
}
}
@ -434,20 +394,17 @@ namespace ICSharpCode.NRefactory.Parser.VB
switch ( char . ToUpper ( ( char ) ReaderPeek ( ) ) ) {
switch ( char . ToUpper ( ( char ) ReaderPeek ( ) ) ) {
case 'R' :
case 'R' :
case '#' :
case '#' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
isdouble = true ;
isdouble = true ;
break ;
break ;
case 'D' :
case 'D' :
case '@' :
case '@' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
isdecimal = true ;
isdecimal = true ;
break ;
break ;
case 'F' :
case 'F' :
case '!' :
case '!' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
issingle = true ;
issingle = true ;
break ;
break ;
}
}
@ -464,7 +421,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
return new Token ( Tokens . LiteralDouble , x , y , sb . ToString ( ) , Double . Parse ( digit , CultureInfo . InvariantCulture ) ) ;
return new Token ( Tokens . LiteralDouble , x , y , sb . ToString ( ) , Double . Parse ( digit , CultureInfo . InvariantCulture ) ) ;
}
}
} catch ( FormatException ) {
} catch ( FormatException ) {
errors . Error ( line , c ol, String . Format ( "{0} is not a parseable number" , digit ) ) ;
errors . Error ( Line , C ol, String . Format ( "{0} is not a parseable number" , digit ) ) ;
if ( issingle )
if ( issingle )
return new Token ( Tokens . LiteralSingle , x , y , sb . ToString ( ) , 0f ) ;
return new Token ( Tokens . LiteralSingle , x , y , sb . ToString ( ) , 0f ) ;
if ( isdecimal )
if ( isdecimal )
@ -479,11 +436,11 @@ namespace ICSharpCode.NRefactory.Parser.VB
try {
try {
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , Int64 . Parse ( digit , ishex ? NumberStyles . HexNumber : NumberStyles . Number ) ) ;
} catch ( FormatException ) {
} catch ( FormatException ) {
errors . Error ( line , c ol, String . Format ( "{0} is not a parseable number" , digit ) ) ;
errors . Error ( Line , C ol, String . Format ( "{0} is not a parseable number" , digit ) ) ;
// fallback, when nothing helps :)
// fallback, when nothing helps :)
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , 0 ) ;
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , 0 ) ;
} catch ( OverflowException ) {
} catch ( OverflowException ) {
errors . Error ( line , c ol, String . Format ( "{0} is too long for a integer literal" , digit ) ) ;
errors . Error ( Line , C ol, String . Format ( "{0} is too long for a integer literal" , digit ) ) ;
// fallback, when nothing helps :)
// fallback, when nothing helps :)
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , 0 ) ;
token = new Token ( Tokens . LiteralInteger , x , y , sb . ToString ( ) , 0 ) ;
}
}
@ -494,7 +451,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
void ReadPreprocessorDirective ( )
void ReadPreprocessorDirective ( )
{
{
Point start = new Point ( c ol - 1 , l ine) ;
Point start = new Point ( C ol - 1 , L ine) ;
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 ) ) ;
@ -505,19 +462,18 @@ namespace ICSharpCode.NRefactory.Parser.VB
char ch = '\0' ;
char ch = '\0' ;
sb . Length = 0 ;
sb . Length = 0 ;
int nextChar ;
int nextChar ;
while ( ( nextChar = reader . Read ( ) ) ! = - 1 ) {
while ( ( nextChar = Reader Read( ) ) ! = - 1 ) {
ch = ( char ) nextChar ;
ch = ( char ) nextChar ;
+ + col ;
if ( ch = = '#' ) {
if ( ch = = '#' ) {
break ;
break ;
} else if ( ch = = '\n' ) {
} else if ( ch = = '\n' ) {
errors . Error ( line , c ol, String . Format ( "No return allowed inside Date literal" ) ) ;
errors . Error ( Line , C ol, String . Format ( "No return allowed inside Date literal" ) ) ;
} else {
} else {
sb . Append ( ch ) ;
sb . Append ( ch ) ;
}
}
}
}
if ( ch ! = '#' ) {
if ( ch ! = '#' ) {
errors . Error ( line , c ol, String . Format ( "End of File reached before Date literal terminated" ) ) ;
errors . Error ( Line , C ol, String . Format ( "End of File reached before Date literal terminated" ) ) ;
}
}
return sb . ToString ( ) ;
return sb . ToString ( ) ;
}
}
@ -527,41 +483,38 @@ namespace ICSharpCode.NRefactory.Parser.VB
char ch = '\0' ;
char ch = '\0' ;
sb . Length = 0 ;
sb . Length = 0 ;
int nextChar ;
int nextChar ;
while ( ( nextChar = reader . Read ( ) ) ! = - 1 ) {
while ( ( nextChar = Reader Read( ) ) ! = - 1 ) {
ch = ( char ) nextChar ;
ch = ( char ) nextChar ;
+ + col ;
if ( ch = = '"' ) {
if ( ch = = '"' ) {
if ( ReaderPeek ( ) ! = - 1 & & ReaderPeek ( ) = = '"' ) {
if ( ReaderPeek ( ) ! = - 1 & & ReaderPeek ( ) = = '"' ) {
sb . Append ( '"' ) ;
sb . Append ( '"' ) ;
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
} else {
} else {
break ;
break ;
}
}
} else if ( ch = = '\n' ) {
} else if ( ch = = '\n' ) {
errors . Error ( line , c ol, String . Format ( "No return allowed inside String literal" ) ) ;
errors . Error ( Line , C ol, String . Format ( "No return allowed inside String literal" ) ) ;
} else {
} else {
sb . Append ( ch ) ;
sb . Append ( ch ) ;
}
}
}
}
if ( ch ! = '"' ) {
if ( ch ! = '"' ) {
errors . Error ( line , c ol, String . Format ( "End of File reached before String terminated " ) ) ;
errors . Error ( Line , C ol, String . Format ( "End of File reached before String terminated " ) ) ;
}
}
return sb . ToString ( ) ;
return sb . ToString ( ) ;
}
}
void ReadComment ( )
void ReadComment ( )
{
{
Point startPos = new Point ( col , l ine) ;
Point startPos = new Point ( Col , L ine) ;
sb . Length = 0 ;
sb . Length = 0 ;
StringBuilder curWord = specialCommentHash ! = null ? new StringBuilder ( ) : null ;
StringBuilder curWord = specialCommentHash ! = null ? new StringBuilder ( ) : null ;
int missingApostrophes = 2 ; // no. of ' missing until it is a documentation comment
int missingApostrophes = 2 ; // no. of ' missing until it is a documentation comment
int x = c ol;
int x = C ol;
int y = l ine;
int y = L ine;
int nextChar ;
int nextChar ;
while ( ( nextChar = reader . Read ( ) ) ! = - 1 ) {
while ( ( nextChar = Reader Read( ) ) ! = - 1 ) {
char ch = ( char ) nextChar ;
char ch = ( char ) nextChar ;
+ + col ;
if ( HandleLineEnd ( ch ) ) {
if ( HandleLineEnd ( ch ) ) {
break ;
break ;
@ -588,9 +541,9 @@ namespace ICSharpCode.NRefactory.Parser.VB
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 , l ine) ;
Point p = new Point ( Col , L ine) ;
string comment = ReadToEOL ( ) ;
string comment = ReadToEOL ( ) ;
tagComments . Add ( new TagComment ( tag , comment , p , new Point ( col , l ine) ) ) ;
tagComments . Add ( new TagComment ( tag , comment , p , new Point ( Col , L ine) ) ) ;
sb . Append ( comment ) ;
sb . Append ( comment ) ;
break ;
break ;
}
}
@ -601,19 +554,18 @@ namespace ICSharpCode.NRefactory.Parser.VB
specialTracker . StartComment ( CommentType . SingleLine , startPos ) ;
specialTracker . StartComment ( CommentType . SingleLine , startPos ) ;
}
}
specialTracker . AddString ( sb . ToString ( ) ) ;
specialTracker . AddString ( sb . ToString ( ) ) ;
specialTracker . FinishComment ( new Point ( col , l ine) ) ;
specialTracker . FinishComment ( new Point ( Col , L ine) ) ;
}
}
Token ReadOperator ( char ch )
Token ReadOperator ( char ch )
{
{
int x = c ol;
int x = C ol;
int y = l ine;
int y = L ine;
switch ( ch ) {
switch ( ch ) {
case '+' :
case '+' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . PlusAssign , x , y ) ;
return new Token ( Tokens . PlusAssign , x , y ) ;
default :
default :
break ;
break ;
@ -622,8 +574,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '-' :
case '-' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . MinusAssign , x , y ) ;
return new Token ( Tokens . MinusAssign , x , y ) ;
default :
default :
break ;
break ;
@ -632,8 +583,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '*' :
case '*' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . TimesAssign , x , y ) ;
return new Token ( Tokens . TimesAssign , x , y ) ;
default :
default :
break ;
break ;
@ -642,8 +592,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '/' :
case '/' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . DivAssign , x , y ) ;
return new Token ( Tokens . DivAssign , x , y ) ;
default :
default :
break ;
break ;
@ -652,8 +601,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '\\' :
case '\\' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . DivIntegerAssign , x , y ) ;
return new Token ( Tokens . DivIntegerAssign , x , y ) ;
default :
default :
break ;
break ;
@ -662,8 +610,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '&' :
case '&' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . ConcatStringAssign , x , y ) ;
return new Token ( Tokens . ConcatStringAssign , x , y ) ;
default :
default :
break ;
break ;
@ -672,8 +619,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '^' :
case '^' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . PowerAssign , x , y ) ;
return new Token ( Tokens . PowerAssign , x , y ) ;
default :
default :
break ;
break ;
@ -686,22 +632,18 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '<' :
case '<' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . LessEqual , x , y ) ;
return new Token ( Tokens . LessEqual , x , y ) ;
case '>' :
case '>' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . NotEqual , x , y ) ;
return new Token ( Tokens . NotEqual , x , y ) ;
case '<' :
case '<' :
reader . Read ( ) ;
Reader Read( ) ;
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
col + = 2 ;
return new Token ( Tokens . ShiftLeftAssign , x , y ) ;
return new Token ( Tokens . ShiftLeftAssign , x , y ) ;
default :
default :
+ + col ;
break ;
break ;
}
}
return new Token ( Tokens . ShiftLeft , x , y ) ;
return new Token ( Tokens . ShiftLeft , x , y ) ;
@ -710,19 +652,16 @@ namespace ICSharpCode.NRefactory.Parser.VB
case '>' :
case '>' :
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
+ + col ;
return new Token ( Tokens . GreaterEqual , x , y ) ;
return new Token ( Tokens . GreaterEqual , x , y ) ;
case '>' :
case '>' :
reader . Read ( ) ;
Reader Read( ) ;
if ( ReaderPeek ( ) ! = - 1 ) {
if ( ReaderPeek ( ) ! = - 1 ) {
switch ( ReaderPeek ( ) ) {
switch ( ReaderPeek ( ) ) {
case '=' :
case '=' :
reader . Read ( ) ;
ReaderRead ( ) ;
col + = 2 ;
return new Token ( Tokens . ShiftRightAssign , x , y ) ;
return new Token ( Tokens . ShiftRightAssign , x , y ) ;
default :
default :
+ + col ;
break ;
break ;
}
}
}
}
@ -735,8 +674,7 @@ namespace ICSharpCode.NRefactory.Parser.VB
// Prevent OverflowException when Peek returns -1
// Prevent OverflowException when Peek returns -1
int tmp = ReaderPeek ( ) ;
int tmp = ReaderPeek ( ) ;
if ( tmp > 0 & & Char . IsDigit ( ( char ) tmp ) ) {
if ( tmp > 0 & & Char . IsDigit ( ( char ) tmp ) ) {
- - col ;
return ReadDigit ( '.' , Col ) ;
return ReadDigit ( '.' , col ) ;
}
}
return new Token ( Tokens . Dot , x , y ) ;
return new Token ( Tokens . Dot , x , y ) ;
case '(' :
case '(' :