@@ -31,6 +31,7 @@ pub fn Parser(comptime _T: type) type {
31
31
pub const map = mecha .map ;
32
32
pub const opt = mecha .opt ;
33
33
pub const peek = mecha .peek ;
34
+ pub const not = mecha .not ;
34
35
};
35
36
}
36
37
@@ -362,14 +363,22 @@ test "opt" {
362
363
try expectOk (? u8 , 0 , null , try p1 .parse (fa , "1" ));
363
364
}
364
365
365
- pub fn peek (comptime parser : anytype ) mecha.Parser (void ) {
366
+ pub fn not (comptime parser : anytype ) Parser (void ) {
367
+ return _peek (parser , true );
368
+ }
369
+
370
+ pub fn peek (comptime parser : anytype ) Parser (void ) {
371
+ return _peek (parser , false );
372
+ }
373
+
374
+ pub fn _peek (comptime parser : anytype , _not : bool ) mecha.Parser (void ) {
366
375
const Res = mecha .Result (void );
367
376
return .{ .parse = struct {
368
377
fn parse (allocator : mem.Allocator , str : []const u8 ) mecha.Error ! Res {
369
378
const res = try parser .parse (allocator , str );
370
379
return switch (res .value ) {
371
- .ok = > Res .ok (0 , {}),
372
- .err = > Res .err (0 ),
380
+ .ok = > if ( _not ) Res . err ( 0 ) else Res .ok (0 , {}),
381
+ .err = > if ( _not ) Res . ok ( 0 , {}) else Res .err (0 ),
373
382
};
374
383
}
375
384
}.parse };
0 commit comments