for now no escaping comment

Signed-off-by: kjuulh <contact@kjuulh.io>
This commit is contained in:
Kasper Juul Hermansen 2023-07-04 20:56:48 +02:00
parent 7a3c98ac76
commit c34df2ccaa
Signed by: kjuulh
GPG Key ID: 57B6E1465221F912
6 changed files with 615 additions and 541 deletions

21
corpus/extras.txt Normal file
View File

@ -0,0 +1,21 @@
===
Comments
===
GET https://somewhere.com # some comment
# comment
HTTP 200 # comment
---
(source_file
(request_declaration
(request_literal)
(url))
(comment)
(comment)
(response
(scheme_literal)
(status_code_pattern))
(comment))

View File

@ -47,7 +47,7 @@ More Headers
POST https://somewhere.com?query=something
some: header
A123a-123: someA asdfasdf asdf c123
A123a-123: someAasdfasdfasdfc123
---
@ -55,9 +55,13 @@ A123a-123: someA asdfasdf asdf c123
(request_declaration
(request_literal)
(url))
(header_declaration
(header_name)
(header_value)))
(header_declaration
(header_name)
(header_value))
(header_declaration
(header_name)
(header_value))
)
===
HTTP Status codes 200
@ -92,3 +96,23 @@ HTTP 302
(response
(scheme_literal)
(status_code_pattern)))
===
HTTP Status codes 302
===
POST https://somewhere.com?query=something
Header: something
HTTP 302
---
(source_file
(request_declaration
(request_literal)
(url))
(header_declaration
(header_name)
(header_value))
(response
(scheme_literal)
(status_code_pattern)))

View File

@ -1,6 +1,11 @@
module.exports = grammar({
name: "hurl",
extras: $ => [
$.comment,
/\s/
],
rules: {
source_file: ($) => repeat($._statement),
@ -28,7 +33,7 @@ module.exports = grammar({
field("header_value", $.header_value)
),
http_response_declaration: $ => seq($.scheme_literal, $._space_literal, $.status_code_pattern),
http_response_declaration: $ => seq($.scheme_literal, $.status_code_pattern),
// literals
@ -55,14 +60,15 @@ module.exports = grammar({
scheme_literal: $ => "HTTP",
_space_literal: $ => " ",
// patterns
comment: $ => token(prec(-10, /#.*/)),
status_code_pattern: $ => /[\d]{3}/,
header_name: ($) => /[a-zA-Z-_0-9]+/,
header_value: ($) =>
/[a-zA-Z-_0-9\s:;\.,\\\/\"\'\?\!\(\)\{\}\[\]@<>=\-\+\*\#\$\&`|~^%]+/,
/[a-zA-Z\-_0-9\/\\]+/,
url: ($) => /\S+/,
},

View File

@ -88,10 +88,6 @@
"type": "SYMBOL",
"name": "scheme_literal"
},
{
"type": "SYMBOL",
"name": "_space_literal"
},
{
"type": "SYMBOL",
"name": "status_code_pattern"
@ -176,9 +172,16 @@
"type": "STRING",
"value": "HTTP"
},
"_space_literal": {
"type": "STRING",
"value": " "
"comment": {
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -10,
"content": {
"type": "PATTERN",
"value": "#.*"
}
}
},
"status_code_pattern": {
"type": "PATTERN",
@ -190,7 +193,7 @@
},
"header_value": {
"type": "PATTERN",
"value": "[a-zA-Z-_0-9\\s:;\\.,\\\\\\/\\\"\\'\\?\\!\\(\\)\\{\\}\\[\\]@<>=\\-\\+\\*\\#\\$\\&`|~^%]+"
"value": "[a-zA-Z\\-_0-9\\/\\\\]+"
},
"url": {
"type": "PATTERN",
@ -198,6 +201,10 @@
}
},
"extras": [
{
"type": "SYMBOL",
"name": "comment"
},
{
"type": "PATTERN",
"value": "\\s"

View File

@ -162,6 +162,10 @@
"type": "VIEW",
"named": false
},
{
"type": "comment",
"named": true
},
{
"type": "header_name",
"named": true

File diff suppressed because it is too large Load Diff