fix: free text

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-07-04 23:01:24 +02:00
parent 20ea4b66b9
commit ce031caef4
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
7 changed files with 4454 additions and 2254 deletions

View File

@ -20,3 +20,21 @@ HTTP 200
(scheme_literal)
(status_code_pattern))
(comment))
===
Identifier
===
SOMETHING
---
(source_file
(request_declaration
(request_literal)
(url))
(comment)
(comment)
(response
(scheme_literal)
(status_code_pattern))
(comment))

View File

@ -140,3 +140,53 @@ HTTP 302
(response
(scheme_literal)
(status_code_pattern)))
===
Request text body
===
POST https://somewhere.com?query=something
```
{
"some-name": "some-value"
}
```
HTTP 302
---
(source_file
(request_declaration
(request_literal)
(url))
(body
(text_body_declaration))
(response
(scheme_literal)
(status_code_pattern)))
===
Request text body json
===
POST https://somewhere.com?query=something
```json
{
"some-name": "some-value"
}
```
HTTP 302
---
(source_file
(request_declaration
(request_literal)
(url))
(body
(text_body_declaration))
(response
(scheme_literal)
(status_code_pattern)))

View File

@ -14,6 +14,8 @@ const PREC = {
module.exports = grammar({
name: "hurl",
word: $ => $.identifier,
extras: $ => [
$.comment,
],
@ -45,10 +47,12 @@ module.exports = grammar({
),
request_body_declaration: $ => choice(
$.json_request_declaration
$.json_request_declaration,
$.text_body_declaration
),
json_request_declaration: $ => prec.left(PREC.body, seq(/\{/, optional(repeat(choice(/\n/))), repeat(seq($._line, NL)), /\}\n\n/)),
text_body_declaration: $ => prec.left(PREC.body, seq(/```/, optional(repeat(choice(/\n/))), repeat(seq($._line, NL)), /```\n\n/)),
header_declaration: ($) =>
@ -67,7 +71,7 @@ module.exports = grammar({
_literal: ($) => choice($.request_literal, $.assert_literal),
request_literal: (_$) =>
request_literal: ($) =>
choice(
"GET",
"POST",
@ -83,7 +87,8 @@ module.exports = grammar({
"LOCK",
"UNLOCK",
"PROPFIND",
"VIEW"
"VIEW",
$.const_pattern
),
@ -101,8 +106,7 @@ module.exports = grammar({
// patterns
//comment: _ => prec.left(PREC.comment, token(seq("#", /.*/, optional(NL)))),
//comment_raw: _ => token(seq("#", /.*/, optional(NL))),
const_pattern: $ => /[A-Z_0-9\/\\\d]+/,
comment: _ => prec.left(PREC.comment, token(seq("#", /.*/, NL))),
status_code_pattern: $ => /[\d]{3}/,
header_name: ($) => /[a-zA-Z-_0-9]+/,
@ -111,6 +115,7 @@ module.exports = grammar({
url: ($) => /\S+/,
_line: _ => /[^\n]+/,
identifier: _ => /[A-Za-z_.\d\u00A1-\uFFFF-]+/,
_whitespace: _ => repeat1(/[\t\v ]/),
},
});

View File

@ -1 +1,3 @@
(json_request_declaration) @json
(text_body_declaration) @markdown

View File

@ -1,5 +1,6 @@
{
"name": "hurl",
"word": "identifier",
"rules": {
"source_file": {
"type": "REPEAT",
@ -111,6 +112,10 @@
{
"type": "SYMBOL",
"name": "json_request_declaration"
},
{
"type": "SYMBOL",
"name": "text_body_declaration"
}
]
},
@ -170,6 +175,62 @@
]
}
},
"text_body_declaration": {
"type": "PREC_LEFT",
"value": 5,
"content": {
"type": "SEQ",
"members": [
{
"type": "PATTERN",
"value": "```"
},
{
"type": "CHOICE",
"members": [
{
"type": "REPEAT",
"content": {
"type": "CHOICE",
"members": [
{
"type": "PATTERN",
"value": "\\n"
}
]
}
},
{
"type": "BLANK"
}
]
},
{
"type": "REPEAT",
"content": {
"type": "SEQ",
"members": [
{
"type": "SYMBOL",
"name": "_line"
},
{
"type": "IMMEDIATE_TOKEN",
"content": {
"type": "PATTERN",
"value": "[\\r\\n]+"
}
}
]
}
},
{
"type": "PATTERN",
"value": "```\\n\\n"
}
]
}
},
"header_declaration": {
"type": "SEQ",
"members": [
@ -316,6 +377,10 @@
{
"type": "STRING",
"value": "VIEW"
},
{
"type": "SYMBOL",
"name": "const_pattern"
}
]
},
@ -356,6 +421,10 @@
"type": "STRING",
"value": "HTTP"
},
"const_pattern": {
"type": "PATTERN",
"value": "[A-Z_0-9\\/\\\\\\d]+"
},
"comment": {
"type": "PREC_LEFT",
"value": 1,
@ -403,6 +472,10 @@
"type": "PATTERN",
"value": "[^\\n]+"
},
"identifier": {
"type": "PATTERN",
"value": "[A-Za-z_.\\d\\u00A1-\\uFFFF-]+"
},
"_whitespace": {
"type": "REPEAT1",
"content": {

View File

@ -30,6 +30,10 @@
{
"type": "json_request_declaration",
"named": true
},
{
"type": "text_body_declaration",
"named": true
}
]
}
@ -103,7 +107,17 @@
{
"type": "request_literal",
"named": true,
"fields": {}
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "const_pattern",
"named": true
}
]
}
},
{
"type": "response",
@ -155,6 +169,11 @@
]
}
},
{
"type": "text_body_declaration",
"named": true,
"fields": {}
},
{
"type": ":",
"named": false
@ -255,6 +274,10 @@
"type": "]",
"named": false
},
{
"type": "const_pattern",
"named": true
},
{
"type": "header_name",
"named": true

File diff suppressed because it is too large Load Diff