@@ -149,6 +149,7 @@ pub struct SelectArm<'self> {
149
149
pub struct Parser < ' self > {
150
150
priv input : & ' self str ,
151
151
priv cur: str:: CharOffsetIterator < ' self > ,
152
+ priv depth : uint ,
152
153
}
153
154
154
155
impl < ' self > iterator:: Iterator < Piece < ' self > > for Parser < ' self > {
@@ -168,6 +169,11 @@ impl<'self> iterator::Iterator<Piece<'self>> for Parser<'self> {
168
169
self . escape ( ) ; // ensure it's a valid escape sequence
169
170
Some ( String ( self . string ( pos + 1 ) ) ) // skip the '\' character
170
171
}
172
+ Some ( ( _, '}' ) ) if self . depth == 0 => {
173
+ self . cur . next ( ) ;
174
+ self . err ( ~"unmatched `} ` found") ;
175
+ None
176
+ }
171
177
Some ( ( _, '}' ) ) | None => { None }
172
178
Some ( ( pos, _) ) => {
173
179
Some ( String ( self . string ( pos) ) )
@@ -182,6 +188,7 @@ impl<'self> Parser<'self> {
182
188
Parser {
183
189
input : s,
184
190
cur : s. char_offset_iter ( ) ,
191
+ depth : 0 ,
185
192
}
186
193
}
187
194
@@ -393,7 +400,9 @@ impl<'self> Parser<'self> {
393
400
if !self . wsconsume ( '{' ) {
394
401
self . err ( ~"selector must be followed by `{ `") ;
395
402
}
403
+ self . depth += 1 ;
396
404
let pieces = self . collect ( ) ;
405
+ self . depth -= 1 ;
397
406
if !self . wsconsume ( '}' ) {
398
407
self . err ( ~"selector case must be terminated by `} `") ;
399
408
}
@@ -494,7 +503,9 @@ impl<'self> Parser<'self> {
494
503
if !self . wsconsume ( '{' ) {
495
504
self . err ( ~"selector must be followed by `{ `") ;
496
505
}
506
+ self . depth += 1 ;
497
507
let pieces = self . collect ( ) ;
508
+ self . depth -= 1 ;
498
509
if !self . wsconsume ( '}' ) {
499
510
self . err ( ~"selector case must be terminated by `} `") ;
500
511
}
0 commit comments