mirror of
https://github.com/alecthomas/chroma.git
synced 2025-01-28 03:29:41 +02:00
support HTTP/2 and HTTP/3 (#774)
This commit is contained in:
parent
357f0cbe40
commit
4f02bc5f68
@ -22,8 +22,8 @@ var HTTP = Register(httpBodyContentTypeLexer(MustNewLexer(
|
||||
func httpRules() Rules {
|
||||
return Rules{
|
||||
"root": {
|
||||
{`(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH|CONNECT)( +)([^ ]+)( +)(HTTP)(/)([12]\.[01])(\r?\n|\Z)`, ByGroups(NameFunction, Text, NameNamespace, Text, KeywordReserved, Operator, LiteralNumber, Text), Push("headers")},
|
||||
{`(HTTP)(/)([12]\.[01])( +)(\d{3})( +)([^\r\n]+)(\r?\n|\Z)`, ByGroups(KeywordReserved, Operator, LiteralNumber, Text, LiteralNumber, Text, NameException, Text), Push("headers")},
|
||||
{`(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH|CONNECT)( +)([^ ]+)( +)(HTTP)(/)([123](?:\.[01])?)(\r?\n|\Z)`, ByGroups(NameFunction, Text, NameNamespace, Text, KeywordReserved, Operator, LiteralNumber, Text), Push("headers")},
|
||||
{`(HTTP)(/)([123](?:\.[01])?)( +)(\d{3})( +)([^\r\n]+)(\r?\n|\Z)`, ByGroups(KeywordReserved, Operator, LiteralNumber, Text, LiteralNumber, Text, NameException, Text), Push("headers")},
|
||||
},
|
||||
"headers": {
|
||||
{`([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|\Z)`, EmitterFunc(httpHeaderBlock), nil},
|
||||
|
5
lexers/testdata/http.2.0.actual
vendored
Normal file
5
lexers/testdata/http.2.0.actual
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
GET /foo HTTP/2.0
|
||||
Content-Type: application/json
|
||||
User-Agent: foo
|
||||
|
||||
{"hello": "world"}
|
27
lexers/testdata/http.2.0.expected
vendored
Normal file
27
lexers/testdata/http.2.0.expected
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
[
|
||||
{"type":"NameFunction","value":"GET"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameNamespace","value":"/foo"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordReserved","value":"HTTP"},
|
||||
{"type":"Operator","value":"/"},
|
||||
{"type":"LiteralNumber","value":"2.0"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Name","value":"Content-Type"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Literal","value":"application/json"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Name","value":"User-Agent"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Literal","value":"foo"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"NameTag","value":"\"hello\""},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralStringDouble","value":"\"world\""},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n"}
|
||||
]
|
2
lexers/testdata/http.2.actual
vendored
2
lexers/testdata/http.2.actual
vendored
@ -1,4 +1,4 @@
|
||||
GET /foo HTTP/2.0
|
||||
GET /foo HTTP/2
|
||||
Content-Type: application/json
|
||||
User-Agent: foo
|
||||
|
||||
|
2
lexers/testdata/http.2.expected
vendored
2
lexers/testdata/http.2.expected
vendored
@ -5,7 +5,7 @@
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordReserved","value":"HTTP"},
|
||||
{"type":"Operator","value":"/"},
|
||||
{"type":"LiteralNumber","value":"2.0"},
|
||||
{"type":"LiteralNumber","value":"2"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Name","value":"Content-Type"},
|
||||
{"type":"Operator","value":":"},
|
||||
|
5
lexers/testdata/http.3.actual
vendored
Normal file
5
lexers/testdata/http.3.actual
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
GET /foo HTTP/3
|
||||
Content-Type: application/json
|
||||
User-Agent: foo
|
||||
|
||||
{"hello": "world"}
|
27
lexers/testdata/http.3.expected
vendored
Normal file
27
lexers/testdata/http.3.expected
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
[
|
||||
{"type":"NameFunction","value":"GET"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"NameNamespace","value":"/foo"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"KeywordReserved","value":"HTTP"},
|
||||
{"type":"Operator","value":"/"},
|
||||
{"type":"LiteralNumber","value":"3"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Name","value":"Content-Type"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Literal","value":"application/json"},
|
||||
{"type":"Text","value":"\n"},
|
||||
{"type":"Name","value":"User-Agent"},
|
||||
{"type":"Operator","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"Literal","value":"foo"},
|
||||
{"type":"Text","value":"\n\n"},
|
||||
{"type":"Punctuation","value":"{"},
|
||||
{"type":"NameTag","value":"\"hello\""},
|
||||
{"type":"Punctuation","value":":"},
|
||||
{"type":"Text","value":" "},
|
||||
{"type":"LiteralStringDouble","value":"\"world\""},
|
||||
{"type":"Punctuation","value":"}"},
|
||||
{"type":"Text","value":"\n"}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user