-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
980d488
commit a933607
Showing
1 changed file
with
19 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,21 @@ | ||
import { Match, RES_FAIL, RES_PARTIAL, Matcher } from "./api"; | ||
import { Match, RES_FAIL, RES_PARTIAL, Matcher, SeqCallback } from "./api"; | ||
import { success } from "./success"; | ||
|
||
export const not = | ||
<T, C, R>(match: Matcher<T, C, R>, callback?): Matcher<T, C, R> => | ||
() => { | ||
let m = match(); | ||
return (ctx, x) => { | ||
const { type } = m(ctx, x); | ||
return type === Match.FAIL ? | ||
success(callback && callback(ctx)) : | ||
type !== Match.PARTIAL ? | ||
// TODO Match.FULL_NC handling? | ||
RES_FAIL : | ||
RES_PARTIAL; | ||
} | ||
}; | ||
export const not = <T, C, R>( | ||
match: Matcher<T, C, R>, | ||
callback?: SeqCallback<T, C, R> | ||
): Matcher<T, C, R> => | ||
() => { | ||
let m = match(); | ||
const buf: T[] = []; | ||
return (ctx, x) => { | ||
buf.push(x); | ||
const { type } = m(ctx, x); | ||
return type === Match.FAIL ? | ||
success(callback && callback(ctx, buf)) : | ||
type !== Match.PARTIAL ? | ||
// TODO Match.FULL_NC handling? | ||
RES_FAIL : | ||
RES_PARTIAL; | ||
} | ||
}; |