-
Notifications
You must be signed in to change notification settings - Fork 0
/
_abnf.ts
37 lines (31 loc) · 881 Bytes
/
_abnf.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { either, namedCapture, sequence, suffix } from "npm:compose-regexp";
import { optimize } from "https://esm.sh/regexp-tree";
const tchar = /[!#$%&'*+.^_`|~\dA-Za-z-]/;
const token = suffix("+", tchar);
const SP = / /;
const OWS = /[ \t]*/;
const BWS = OWS;
const DQUOTE = /"/;
const obsText = /[\x80-\xFF]/;
const HTAB = /\t/;
const qdtext = either(HTAB, SP, "\x21", /[\x23-\x5B/, /[\x5D-\x7E]/, obsText);
const VCHAR = /[\x21-\x7E]/;
const quotedPair = sequence("\\", either(HTAB, SP, VCHAR, obsText));
const quotedString = sequence(
DQUOTE,
suffix("*", either(qdtext, quotedPair)),
DQUOTE,
);
const authParam = sequence(
namedCapture("key", token),
BWS,
"=",
BWS,
either(
namedCapture("token", token),
namedCapture("quotedString", quotedString),
),
);
if (import.meta.main) {
console.log("authParam: ", optimize(authParam).toRegExp());
}