feat: add http response codes

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-07-04 20:07:50 +02:00
parent 8d8a40a3a3
commit 7a3c98ac76
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
5 changed files with 1351 additions and 200 deletions

View File

@ -8,10 +8,11 @@ GET https://somewhere.com
(source_file (source_file
(request_declaration (request_declaration
(request_literal))) (request_literal)
(url)))
=== ===
GET request POST request
=== ===
POST https://somewhere.com?query=something POST https://somewhere.com?query=something
@ -20,4 +21,74 @@ POST https://somewhere.com?query=something
(source_file (source_file
(request_declaration (request_declaration
(request_literal))) (request_literal)
(url)))
===
Headers
===
POST https://somewhere.com?query=something
some: header
---
(source_file
(request_declaration
(request_literal)
(url))
(header_declaration
(header_name)
(header_value)))
===
More Headers
===
POST https://somewhere.com?query=something
some: header
A123a-123: someA asdfasdf asdf c123
---
(source_file
(request_declaration
(request_literal)
(url))
(header_declaration
(header_name)
(header_value)))
===
HTTP Status codes 200
===
POST https://somewhere.com?query=something
HTTP 200
---
(source_file
(request_declaration
(request_literal)
(url))
(response
(scheme_literal)
(status_code_pattern)))
===
HTTP Status codes 302
===
POST https://somewhere.com?query=something
HTTP 302
---
(source_file
(request_declaration
(request_literal)
(url))
(response
(scheme_literal)
(status_code_pattern)))

View File

@ -10,10 +10,27 @@ module.exports = grammar({
choice($._declaration_statement), choice($._declaration_statement),
_declaration_statement: ($) => _declaration_statement: ($) =>
choice($.request_declaration), choice(
$.request_declaration,
$.header_declaration,
alias($.http_response_declaration, $.response),
),
// declarations
request_declaration: ($) => request_declaration: ($) =>
seq($._literal, field("url", $._url)), seq($._literal, field("url", $.url)),
header_declaration: ($) =>
seq(
field("header_name", $.header_name),
":",
field("header_value", $.header_value)
),
http_response_declaration: $ => seq($.scheme_literal, $._space_literal, $.status_code_pattern),
// literals
_literal: ($) => choice($.request_literal), _literal: ($) => choice($.request_literal),
@ -36,6 +53,17 @@ module.exports = grammar({
"VIEW" "VIEW"
), ),
_url: ($) => /\S+/, scheme_literal: $ => "HTTP",
_space_literal: $ => " ",
// patterns
status_code_pattern: $ => /[\d]{3}/,
header_name: ($) => /[a-zA-Z-_0-9]+/,
header_value: ($) =>
/[a-zA-Z-_0-9\s:;\.,\\\/\"\'\?\!\(\)\{\}\[\]@<>=\-\+\*\#\$\&`|~^%]+/,
url: ($) => /\S+/,
}, },
}); });

View File

@ -23,6 +23,19 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "request_declaration" "name": "request_declaration"
},
{
"type": "SYMBOL",
"name": "header_declaration"
},
{
"type": "ALIAS",
"content": {
"type": "SYMBOL",
"name": "http_response_declaration"
},
"named": true,
"value": "response"
} }
] ]
}, },
@ -38,11 +51,53 @@
"name": "url", "name": "url",
"content": { "content": {
"type": "SYMBOL", "type": "SYMBOL",
"name": "_url" "name": "url"
} }
} }
] ]
}, },
"header_declaration": {
"type": "SEQ",
"members": [
{
"type": "FIELD",
"name": "header_name",
"content": {
"type": "SYMBOL",
"name": "header_name"
}
},
{
"type": "STRING",
"value": ":"
},
{
"type": "FIELD",
"name": "header_value",
"content": {
"type": "SYMBOL",
"name": "header_value"
}
}
]
},
"http_response_declaration": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "scheme_literal"
},
{
"type": "SYMBOL",
"name": "_space_literal"
},
{
"type": "SYMBOL",
"name": "status_code_pattern"
}
]
},
"_literal": { "_literal": {
"type": "CHOICE", "type": "CHOICE",
"members": [ "members": [
@ -117,7 +172,27 @@
} }
] ]
}, },
"_url": { "scheme_literal": {
"type": "STRING",
"value": "HTTP"
},
"_space_literal": {
"type": "STRING",
"value": " "
},
"status_code_pattern": {
"type": "PATTERN",
"value": "[\\d]{3}"
},
"header_name": {
"type": "PATTERN",
"value": "[a-zA-Z-_0-9]+"
},
"header_value": {
"type": "PATTERN",
"value": "[a-zA-Z-_0-9\\s:;\\.,\\\\\\/\\\"\\'\\?\\!\\(\\)\\{\\}\\[\\]@<>=\\-\\+\\*\\#\\$\\&`|~^%]+"
},
"url": {
"type": "PATTERN", "type": "PATTERN",
"value": "\\S+" "value": "\\S+"
} }

View File

@ -1,8 +1,45 @@
[ [
{
"type": "header_declaration",
"named": true,
"fields": {
"header_name": {
"multiple": false,
"required": true,
"types": [
{
"type": "header_name",
"named": true
}
]
},
"header_value": {
"multiple": false,
"required": true,
"types": [
{
"type": "header_value",
"named": true
}
]
}
}
},
{ {
"type": "request_declaration", "type": "request_declaration",
"named": true, "named": true,
"fields": {}, "fields": {
"url": {
"multiple": false,
"required": true,
"types": [
{
"type": "url",
"named": true
}
]
}
},
"children": { "children": {
"multiple": false, "multiple": false,
"required": true, "required": true,
@ -19,6 +56,25 @@
"named": true, "named": true,
"fields": {} "fields": {}
}, },
{
"type": "response",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": true,
"types": [
{
"type": "scheme_literal",
"named": true
},
{
"type": "status_code_pattern",
"named": true
}
]
}
},
{ {
"type": "source_file", "type": "source_file",
"named": true, "named": true,
@ -27,13 +83,25 @@
"multiple": true, "multiple": true,
"required": false, "required": false,
"types": [ "types": [
{
"type": "header_declaration",
"named": true
},
{ {
"type": "request_declaration", "type": "request_declaration",
"named": true "named": true
},
{
"type": "response",
"named": true
} }
] ]
} }
}, },
{
"type": ":",
"named": false
},
{ {
"type": "CONNECT", "type": "CONNECT",
"named": false "named": false
@ -93,5 +161,25 @@
{ {
"type": "VIEW", "type": "VIEW",
"named": false "named": false
},
{
"type": "header_name",
"named": true
},
{
"type": "header_value",
"named": true
},
{
"type": "scheme_literal",
"named": true
},
{
"type": "status_code_pattern",
"named": true
},
{
"type": "url",
"named": true
} }
] ]

File diff suppressed because it is too large Load Diff