@@ -159,14 +159,15 @@ class KdlTokenizer {
159
159
this .index += 1 ;
160
160
} else if (c != null && RegExp (r"[0-9\-+]" ).hasMatch (c)) {
161
161
var n = _charAt (this .index + 1 );
162
+ var n2 = _charAt (this .index + 2 );
162
163
if (c == '0' && n != null && RegExp ("[box]" ).hasMatch (n)) {
163
164
this .index += 2 ;
164
165
this .buffer = '' ;
165
- switch (n) {
166
- case 'b' : _setContext ( KdlTokenizerContext .binary); break ;
167
- case 'o' : _setContext ( KdlTokenizerContext .octal); break ;
168
- case 'x' : _setContext ( KdlTokenizerContext .hexadecimal); break ;
169
- }
166
+ _setContext ( _integerContext (n));
167
+ } else if ((c == '-' || c == '+' ) && n == '0' && RegExp ( "[box]" ). hasMatch (n2)) {
168
+ this .index += 3 ;
169
+ this .buffer = c ;
170
+ _setContext ( _integerContext (n2));
170
171
} else {
171
172
_setContext (KdlTokenizerContext .decimal);
172
173
this .index += 1 ;
@@ -388,6 +389,14 @@ class KdlTokenizer {
388
389
this .previousContext = null ;
389
390
}
390
391
392
+ _integerContext (String n) {
393
+ switch (n) {
394
+ case 'b' : return KdlTokenizerContext .binary;
395
+ case 'o' : return KdlTokenizerContext .octal;
396
+ case 'x' : return KdlTokenizerContext .hexadecimal;
397
+ }
398
+ }
399
+
391
400
_parseDecimal (String s) {
392
401
if (RegExp ("[.eE]" ).hasMatch (s)) {
393
402
_checkFloat (s);
@@ -410,17 +419,17 @@ class KdlTokenizer {
410
419
}
411
420
412
421
_parseHexadecimal (String s) {
413
- if (! RegExp (r"^[0-9a-fA-F][0-9a-fA-F_]*$" ).hasMatch (s)) throw "Invalid hexadecimal: ${s }" ;
422
+ if (! RegExp (r"^[+-]?[ 0-9a-fA-F][0-9a-fA-F_]*$" ).hasMatch (s)) throw "Invalid hexadecimal: ${s }" ;
414
423
return [KdlToken .INTEGER , _parseInteger (_munchUnderscores (s), 16 )];
415
424
}
416
425
417
426
_parseOctal (String s) {
418
- if (! RegExp (r"^[0-7][0-7_]*$" ).hasMatch (s)) throw "Invalid octal: ${s }" ;
427
+ if (! RegExp (r"^[+-]?[ 0-7][0-7_]*$" ).hasMatch (s)) throw "Invalid octal: ${s }" ;
419
428
return [KdlToken .INTEGER , _parseInteger (_munchUnderscores (s), 8 )];
420
429
}
421
430
422
431
_parseBinary (String s) {
423
- if (! RegExp (r"^[01][01_]*$" ).hasMatch (s)) throw "Invalid binary: ${s }" ;
432
+ if (! RegExp (r"^[+-]?[ 01][01_]*$" ).hasMatch (s)) throw "Invalid binary: ${s }" ;
424
433
return [KdlToken .INTEGER , _parseInteger (_munchUnderscores (s), 2 )];
425
434
}
426
435
@@ -441,7 +450,7 @@ class KdlTokenizer {
441
450
case r'\/' : return "/" ;
442
451
default : throw "Unexpected escape '${match .group (0 )}'" ;
443
452
}
444
- }).replaceAllMapped (RegExp (r"\\u\{[0-9a-fA-F]{0 ,6}\}" ), (match) {
453
+ }).replaceAllMapped (RegExp (r"\\u\{[0-9a-fA-F]{1 ,6}\}" ), (match) {
445
454
String m = match.group (0 ) ?? '' ;
446
455
int i = int .parse (m.substring (3 , m.length - 1 ), radix: 16 );
447
456
if (i < 0 || i > 0x10FFFF ) {
0 commit comments