-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.js
50 lines (45 loc) · 1.06 KB
/
grammar.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
module.exports = grammar({
name: "hurl",
extras: ($) => [$.comment, $._sp],
rules: {
source_file: ($) => repeat($.request),
request: ($) => seq($._method_section, repeat($.request_section)),
_method_section: ($) =>
seq($.method, $._sp, $.url, repeat1($._lt), repeat($.header)),
method: (_) =>
choice(
"GET",
"HEAD",
"POST",
"PUT",
"DELETE",
"CONNECT",
"OPTIONS",
"TRACE",
"PATCH",
),
url: (_) => /(ftp|http|https):\/\/[^\s"]+(:\d{4})?/,
header: ($) => seq($.key, ":", $.value, repeat1($._lt)),
// key: (_) => /[^#:\n\\]+/,
key: (_) => /[^#:\n\\\[][^#:\n\\]+/,
value: (_) => /[^#\n\\]+/,
request_section: ($) =>
seq(
"[",
choice(
"QueryStringParams",
"FormParams",
"MultipartFormData",
"Cookies",
),
"]",
repeat1($._lt),
repeat($.header),
),
version: (_) => choice("HTTP/1.0", "HTTP/1.1", "HTTP/2", "HTTP/*"),
status: (_) => /\d+/,
comment: ($) => /#[^\n]*/,
_sp: (_) => /[\s\t]/,
_lt: ($) => seq(repeat($._sp), optional($.comment), /[\n]?/),
},
});