1
1
using System ;
2
+ using System . Collections . Generic ;
2
3
using System . Linq ;
3
4
using Winterdom . Viasfora . Rainbow ;
4
5
using Winterdom . Viasfora . Util ;
@@ -11,11 +12,34 @@ public class CSharpBraceScanner : IBraceScanner, IResumeControl {
11
12
const int stMultiLineComment = 4 ;
12
13
const int stIString = 5 ;
13
14
14
- private int status = stText ;
15
- private int nestingLevel = 0 ;
16
- private int istringNestLevel = 0 ;
17
- private bool parsingExpression = false ;
18
- private bool multiLine = false ;
15
+ private int status { get => this . nestings [ this . _nestingIndex ] . status ; set => this . nestings [ this . _nestingIndex ] . status = value ; }
16
+ private int nestingLevel { get => this . nestings [ this . _nestingIndex ] . nestingLevel ; set => this . nestings [ this . _nestingIndex ] . nestingLevel = value ; }
17
+ private bool parsingExpression { get => this . nestings [ this . _nestingIndex ] . parsingExpression ; set => this . nestings [ this . _nestingIndex ] . parsingExpression = value ; }
18
+ private bool multiLine { get => this . nestings [ this . _nestingIndex ] . multiLine ; set => this . nestings [ this . _nestingIndex ] . multiLine = value ; }
19
+
20
+
21
+ private int nestingIndex {
22
+ get {
23
+ return this . _nestingIndex ;
24
+ }
25
+ set {
26
+ if ( value > this . _nestingIndex ) {
27
+ this . nestings . Add ( new NestingOption ( ) { status = this . status , nestingLevel = this . nestingLevel , parsingExpression = this . parsingExpression , multiLine = this . multiLine } ) ;
28
+ } else if ( value < this . _nestingIndex ) {
29
+ this . nestings . RemoveAt ( this . nestings . Count - 1 ) ;
30
+ }
31
+ this . _nestingIndex = value ;
32
+ }
33
+ }
34
+ private int _nestingIndex = 0 ;
35
+ private List < NestingOption > nestings = new List < NestingOption > ( ) { new NestingOption ( ) } ;
36
+
37
+ private class NestingOption {
38
+ public int nestingLevel = 0 ;
39
+ public int status = stText ;
40
+ public bool parsingExpression = false ;
41
+ public bool multiLine = false ;
42
+ }
19
43
20
44
public String BraceList => "(){}[]" ;
21
45
@@ -27,7 +51,7 @@ public void Reset(int state) {
27
51
this . parsingExpression = ( state & 0x08000000 ) != 0 ;
28
52
this . nestingLevel = ( state & 0xFF0000 ) >> 24 ;
29
53
this . multiLine = ( state & 0x04000000 ) != 0 ;
30
- this . istringNestLevel = ( state & 0xFF00 ) >> 16 ;
54
+ this . nestingIndex = ( state & 0xFF00 ) >> 16 ;
31
55
}
32
56
33
57
public bool CanResume ( CharPos brace ) {
@@ -170,17 +194,18 @@ private bool ParseInterpolatedString(ITextChars tc, ref CharPos pos) {
170
194
//
171
195
// we're inside an interpolated section
172
196
//
173
- if ( tc . Char ( ) == '$' && tc . NChar ( ) == '"' ) {
197
+ if ( tc . Char ( ) == '$' && ( tc . NChar ( ) == '"' ) || ( tc . NNChar ( ) == '"' && tc . NChar ( ) == '@' ) ) {
174
198
// opening nested interpolated string
175
- tc . Skip ( 2 ) ;
199
+ tc . Skip ( tc . NChar ( ) == '"' ? 2 : 3 ) ;
200
+ this . nestingIndex ++ ;
176
201
this . parsingExpression = false ;
177
- this . istringNestLevel ++ ;
178
202
this . nestingLevel = 0 ;
179
- if ( this . ParseInterpolatedString ( tc , ref pos ) )
180
- return true ;
181
- this . istringNestLevel -- ;
182
- this . parsingExpression = true ;
183
- this . status = stIString ;
203
+ //if ( this.ParseInterpolatedString(tc, ref pos) )
204
+ // return true;
205
+ //this.nestingIndex--;
206
+ //this.parsingExpression = true;
207
+ //this.status = stIString;
208
+ return false ;
184
209
} else if ( tc . Char ( ) == '@' && tc . NChar ( ) == '"' ) {
185
210
// opening nested verbatim string
186
211
tc . Skip ( 2 ) ;
@@ -234,15 +259,23 @@ private bool ParseInterpolatedString(ITextChars tc, ref CharPos pos) {
234
259
tc . Skip ( 2 ) ;
235
260
} else if ( tc . Char ( ) == '"' ) {
236
261
// done parsing the interpolated string
237
- this . multiLine = false ;
238
- this . istringNestLevel -- ;
239
- if ( this . istringNestLevel <= 0 ) {
240
- this . istringNestLevel = 0 ;
262
+ //this.multiLine = false;
263
+ //if ( this.nestingIndex - 1 <= 0 ) {
264
+ // this.nestingIndex = 0;
265
+ // this.status = stText;
266
+ //} else {
267
+ // this.status = stIString;
268
+ // this.parsingExpression = true;
269
+ //}
270
+ var indx = this . nestingIndex ;
271
+ if ( indx - 1 < 0 ) {
272
+ this . multiLine = false ;
273
+ this . nestingIndex = 0 ;
241
274
this . status = stText ;
242
275
} else {
243
- this . status = stIString ;
244
- this . parsingExpression = true ;
276
+ this . nestingIndex -- ;
245
277
}
278
+
246
279
tc . Next ( ) ;
247
280
break ;
248
281
} else {
@@ -260,7 +293,7 @@ private int EncodedState() {
260
293
if ( this . multiLine )
261
294
encoded |= 0x04000000 ;
262
295
encoded |= ( this . nestingLevel & 0xFF ) << 24 ;
263
- encoded |= ( this . istringNestLevel & 0xFF ) << 16 ;
296
+ encoded |= ( this . nestingIndex & 0xFF ) << 16 ;
264
297
return encoded ;
265
298
}
266
299
}
0 commit comments