feat: add http response codes

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

View File

@@ -10,10 +10,27 @@ module.exports = grammar({
choice($._declaration_statement),
_declaration_statement: ($) =>
choice($.request_declaration),
choice(
$.request_declaration,
$.header_declaration,
alias($.http_response_declaration, $.response),
),
// declarations
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),
@@ -36,6 +53,17 @@ module.exports = grammar({
"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+/,
},
});