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

View File

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

View File

@ -1,5 +1,6 @@
{ {
"name": "hurl", "name": "hurl",
"word": "identifier",
"rules": { "rules": {
"source_file": { "source_file": {
"type": "REPEAT", "type": "REPEAT",
@ -111,6 +112,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "json_request_declaration" "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": { "header_declaration": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -316,6 +377,10 @@
{ {
"type": "STRING", "type": "STRING",
"value": "VIEW" "value": "VIEW"
},
{
"type": "SYMBOL",
"name": "const_pattern"
} }
] ]
}, },
@ -356,6 +421,10 @@
"type": "STRING", "type": "STRING",
"value": "HTTP" "value": "HTTP"
}, },
"const_pattern": {
"type": "PATTERN",
"value": "[A-Z_0-9\\/\\\\\\d]+"
},
"comment": { "comment": {
"type": "PREC_LEFT", "type": "PREC_LEFT",
"value": 1, "value": 1,
@ -403,6 +472,10 @@
"type": "PATTERN", "type": "PATTERN",
"value": "[^\\n]+" "value": "[^\\n]+"
}, },
"identifier": {
"type": "PATTERN",
"value": "[A-Za-z_.\\d\\u00A1-\\uFFFF-]+"
},
"_whitespace": { "_whitespace": {
"type": "REPEAT1", "type": "REPEAT1",
"content": { "content": {

View File

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

File diff suppressed because it is too large Load Diff