Skip to content

Commit

Permalink
Merge pull request #8 from teto/improve-grammar
Browse files Browse the repository at this point in the history
improve grammar
  • Loading branch information
teto committed Jan 6, 2023
2 parents 758f106 + a820db4 commit 2c6c445
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
build:
$(CC) -fPIC -c src/parser.c -o parser/http.so $(CFLAGS)
$(CC) -fPIC -c src/parser.c -o parser.o $(CFLAGS)
$(CC) -shared -o parser/http.so *.o

8 changes: 2 additions & 6 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ module.exports = grammar(json, {

request: ($) =>
seq(field("method", $.method), $._whitespace, field("url", $.url)),

method: (_) => /(GET|POST|PATCH|DELETE|PUT)/,

url: (_) =>
/((www|http:|https:)\/\/(?:w{1,3}\.)?[^\s.]+(?:\.[a-z]+)*(?::\d+)?|\{\{\w+\}\})([\w.,@?^=%&:\/~+#\{\}\u00C0-\u00FF-]*[\w@?^=%&\/~+#\u00C0-\u00FF-])?/,

Expand All @@ -28,19 +26,17 @@ module.exports = grammar(json, {
$._whitespace,
field("value", $.value)
),

name: (_) => /[A-Za-z-]+/,

value: (_) => /[^\n]+/,

json_file: (_) => seq(/[A-Za-z-_./]+/, ".json"),

external_body: ($) =>
seq(
token("<"),
$._whitespace,
field("json_file", $.json_file),
),
json_file: (_) => seq(/[A-Za-z-_./]+/, ".json"),


comment: ($) => token(seq("#", /.*/)),

Expand Down
20 changes: 20 additions & 0 deletions tests/multiple_requests.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
POST https://reqres.in/api/users
Content-Type: application/json

{
"name": "morpheus",
"job": "leader",
"array": ["a", "b", "c"],
"object_ugly_closing": {
"some_key": "some_value"
}
}

POST https://reqres.in/api/users
Content-Type: application/json

< ./user.json

####
###
GET https://reqres.in/api/users?page=5

0 comments on commit 2c6c445

Please sign in to comment.