Skip to content

Commit be0b6a6

Browse files
feat!: move response out of request node
This enables standalone `response` node. Each `request` and `response` nodes will have their own separate headers and body nodes.
1 parent d2e4e4c commit be0b6a6

File tree

5 files changed

+6478
-8535
lines changed

5 files changed

+6478
-8535
lines changed

grammar.js

Lines changed: 53 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = grammar({
3030
[$._raw_body],
3131
[$._section_content],
3232
],
33-
inline: ($) => [$._target_url_line],
33+
inline: ($) => [$._target_url_line, $.__body],
3434

3535
rules: {
3636
document: ($) => repeat($.section),
@@ -43,28 +43,19 @@ module.exports = grammar({
4343
COMMENT_PREFIX: (_) => COMMENT_PREFIX,
4444

4545
comment: ($) =>
46+
choice(
47+
$._plain_comment,
48+
$._var_comment,
49+
),
50+
_plain_comment: (_) =>
4651
seq(
4752
COMMENT_PREFIX,
48-
choice(
49-
seq(
50-
token(prec(2, "@")),
51-
field("name", $.identifier),
52-
optional(
53-
seq(
54-
choice(WS, "="),
55-
optional(token(prec(1, WS))),
56-
field("value", $.value),
57-
),
58-
),
59-
NL,
60-
),
61-
LINE_TAIL,
62-
),
53+
LINE_TAIL,
6354
),
64-
var_comment: ($) =>
55+
_var_comment: ($) =>
6556
seq(
6657
COMMENT_PREFIX,
67-
token(prec(2, "@")),
58+
token(prec(PREC.VAR_COMMENT_PREFIX, "@")),
6859
field("name", $.identifier),
6960
optional(
7061
seq(
@@ -100,10 +91,9 @@ module.exports = grammar({
10091
seq($.comment, optional($._section_content)),
10192
seq($.variable_declaration, optional($._section_content)),
10293
seq($.pre_request_script, optional($._section_content)),
103-
seq(
104-
// field to easily find request node in each section
105-
field("request", $.request),
106-
),
94+
// field to easily find request node in each section
95+
field("request", $.request),
96+
field("response", $.response),
10797
),
10898

10999
// LIST http verb is arbitrary and required to use vaultproject
@@ -120,14 +110,43 @@ module.exports = grammar({
120110
status_code: (_) => /[1-5]\d{2}/,
121111
status_text: (_) =>
122112
/(Continue|Switching Protocols|Processing|OK|Created|Accepted|Non-Authoritative Information|No Content|Reset Content|Partial Content|Multi-Status|Already Reported|IM Used|Multiple Choices|Moved Permanently|Found|See Other|Not Modified|Use Proxy|Switch Proxy|Temporary Redirect|Permanent Redirect|Bad Request|Unauthorized|Payment Required|Forbidden|Not Found|Method Not Allowed|Not Acceptable|Proxy Authentication Required|Request Timeout|Conflict|Gone|Length Required|Precondition Failed|Payload Too Large|URI Too Long|Unsupported Media Type|Range Not Satisfiable|Expectation Failed|I'm a teapot|Misdirected Request|Unprocessable Entity|Locked|Failed Dependency|Too Early|Upgrade Required|Precondition Required|Too Many Requests|Request Header Fields Too Large|Unavailable For Legal Reasons|Internal Server Error|Not Implemented|Bad Gateway|Service Unavailable|Gateway Timeout|HTTP Version Not Supported|Variant Also Negotiates|Insufficient Storage|Loop Detected|Not Extended|Network Authentication Required)/,
123-
response: ($) =>
113+
__body: ($) =>
124114
seq(
125-
$.http_version,
126-
WS,
127-
$.status_code,
128-
WS,
129-
optional($.status_text),
130-
NL,
115+
repeat1($._blank_line),
116+
prec.right(
117+
repeat(
118+
choice(
119+
alias($._var_comment, $.comment),
120+
field(
121+
"body",
122+
choice(
123+
$.raw_body,
124+
$.multipart_form_data,
125+
$.xml_body,
126+
$.json_body,
127+
$.graphql_body,
128+
$._external_body,
129+
),
130+
),
131+
NL,
132+
$.res_handler_script,
133+
$.res_redirect,
134+
),
135+
),
136+
),
137+
),
138+
response: ($) =>
139+
prec.right(
140+
seq(
141+
$.http_version,
142+
WS,
143+
$.status_code,
144+
WS,
145+
optional($.status_text),
146+
NL,
147+
repeat(field("header", $.header)),
148+
optional($.__body),
149+
),
131150
),
132151

133152
request: ($) =>
@@ -137,35 +156,13 @@ module.exports = grammar({
137156
field("url", $.target_url),
138157
optional(seq(WS, field("version", $.http_version))),
139158
NL,
140-
repeat($.comment),
141-
optional($.response),
142-
repeat(field("header", $.header)),
143-
optional(
144-
seq(
145-
repeat1($._blank_line),
146-
prec.right(
147-
repeat(
148-
choice(
149-
alias($.var_comment, $.comment),
150-
field(
151-
"body",
152-
choice(
153-
$.raw_body,
154-
$.multipart_form_data,
155-
$.xml_body,
156-
$.json_body,
157-
$.graphql_body,
158-
$._external_body,
159-
),
160-
),
161-
NL,
162-
$.res_handler_script,
163-
$.res_redirect,
164-
),
165-
),
166-
),
159+
repeat(
160+
choice(
161+
$.comment,
162+
field("header", $.header)
167163
),
168164
),
165+
optional($.__body),
169166
),
170167
),
171168

0 commit comments

Comments
 (0)