11using SqlServerSimulator . Parser . Tokens ;
2- using System . Text ;
32
43namespace SqlServerSimulator . Parser ;
54
@@ -23,13 +22,13 @@ static class Tokenizer
2322 '@' => ParseAtOrDoubleAtPrefixedString ( command , ref index ) ,
2423 '-' => ParseMinusOrComment ( command , ref index ) ,
2524 '[' => ParseBracketDelimitedString ( command , ref index ) ,
26- '+' => new Plus ( ) ,
27- '*' => new Asterisk ( ) ,
28- '(' => new OpenParentheses ( ) ,
29- ')' => new CloseParentheses ( ) ,
30- ',' => new Comma ( ) ,
31- '.' => new Period ( ) ,
32- ';' => new StatementTerminator ( ) ,
25+ '+' => new Plus ( command , index ) ,
26+ '*' => new Asterisk ( command , index ) ,
27+ '(' => new OpenParentheses ( command , index ) ,
28+ ')' => new CloseParentheses ( command , index ) ,
29+ ',' => new Comma ( command , index ) ,
30+ '.' => new Period ( command , index ) ,
31+ ';' => new StatementTerminator ( command , index ) ,
3332 _ => throw new NotSupportedException ( $ "Simulated tokenizer doesn't know what to do with character '{ command [ index ] } ' at index { index } .")
3433 } ;
3534
@@ -80,7 +79,7 @@ private static Numeric ParseNumeric(string command, ref int index)
8079 break ;
8180 }
8281
83- return new ( new StringBuilder ( command , start , index - start , index -- - start ) ) ;
82+ return new ( command , start , index -- - start ) ;
8483 }
8584
8685 private static Token ParseAtOrDoubleAtPrefixedString ( string command , ref int index )
@@ -110,19 +109,20 @@ private static Token ParseAtOrDoubleAtPrefixedString(string command, ref int ind
110109 break ;
111110 }
112111
113- return doubleAt
114- ? new DoubleAtPrefixedString ( new StringBuilder ( command , start + 2 , index -- - ( start + 2 ) , index - ( start + 2 ) - 1 ) )
115- : new AtPrefixedString ( new StringBuilder ( command , start + 1 , index -- - ( start + 1 ) , index - ( start + 1 ) - 1 ) ) ;
112+ return doubleAt ?
113+ new DoubleAtPrefixedString ( command , start , index -- - start ) :
114+ new AtPrefixedString ( command , start , index -- - start ) ;
116115 }
117116
118117 private static Token ParseMinusOrComment ( string command , ref int index )
119118 {
119+ var start = index ;
120120 if ( ++ index == command . Length )
121- return new Minus ( ) ;
121+ return new Minus ( command , -- index ) ;
122122 if ( command [ index ] != '-' )
123123 {
124124 index -- ;
125- return new Minus ( ) ;
125+ return new Minus ( command , index ) ;
126126 }
127127
128128 while ( ++ index < command . Length )
@@ -131,11 +131,11 @@ private static Token ParseMinusOrComment(string command, ref int index)
131131 {
132132 case '\r ' :
133133 case '\n ' :
134- return new Comment ( ) ;
134+ return new Comment ( command , start , -- index ) ;
135135 }
136136 }
137137
138- return new Comment ( ) ;
138+ return new Comment ( command , start , -- index ) ;
139139 }
140140
141141 private static BracketDelimitedString ParseBracketDelimitedString ( string command , ref int index )
@@ -150,6 +150,6 @@ private static BracketDelimitedString ParseBracketDelimitedString(string command
150150 break ;
151151 }
152152
153- return new ( new StringBuilder ( command , start + 1 , index - start - 2 , index -- - start - 2 ) ) ;
153+ return new ( command . Substring ( start + 1 , index - start - 2 ) , command , start , index -- - start ) ;
154154 }
155155}
0 commit comments