Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(response): parse response #26

Merged
merged 10 commits into from
Apr 19, 2024
Merged
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ prepend it to rtp with `set rtp^=/path/to/tree-sitter-http`.

- [x] variable
- [x] comment
- [x] request
- [x] request
- [x] method
- [x] target_url
- [x] scheme
Expand All @@ -31,6 +31,7 @@ prepend it to rtp with `set rtp^=/path/to/tree-sitter-http`.
- [ ] fragment #
- [x] http-version
- [x] params
- [x] response
- [x] header
- [x] body
- [x] json
Expand Down
12 changes: 6 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ module.exports = grammar({
comment: (_) => token(seq("#", /.*/)),

// LIST http verb is arbitrary and required to use vaultproject
method: ($) =>
choice(
/(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|LIST)/,
$.const_spec,
NTBBloodbath marked this conversation as resolved.
Show resolved Hide resolved
),
method: ($) => /(OPTIONS|GET|HEAD|POST|PUT|DELETE|TRACE|CONNECT|PATCH|LIST)/,

host: ($) => seq($.identifier, optional($.port)),
port: ($) => seq(":", /\d+/),
Expand Down Expand Up @@ -103,13 +99,18 @@ module.exports = grammar({
),
),

status_code: ($) => /[1-5]\d{2}/,
status_text: ($) => /(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)/,
response: ($) => seq($.http_version, $._whitespace, $.status_code, $._whitespace, $.status_text),

request: ($) =>
prec.right(
seq(
$.method,
$._whitespace,
$.target_url,
optional(seq($._whitespace, $.http_version)),
optional(seq(NL, $.response)),
NL,
repeat($.header),
repeat(
Expand Down Expand Up @@ -248,7 +249,6 @@ module.exports = grammar({
)),
),

const_spec: (_) => /[A-Z][A-Z\\d_]+/,
identifier: (_) => /[A-Za-z_.\$\d\u00A1-\uFFFF-]+/,
query_key: (_) => /[^&#=\n]+/,
param: (_) => /[^&#\n]+/,
Expand Down
7 changes: 4 additions & 3 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
; Methods
(method) @function.method

; Constants
(const_spec) @constant

; Headers
(header
name: (name) @constant)
Expand Down Expand Up @@ -43,6 +40,10 @@

(http_version) @constant

; Response
(status_code) @number
(status_text) @string

(string) @string

(number) @number
Expand Down
74 changes: 59 additions & 15 deletions src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 39 additions & 19 deletions src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading