mirror of
https://github.com/alecthomas/chroma.git
synced 2025-11-29 22:47:29 +02:00
feat: support HTTP/2 in HTTP lexer
This commit is contained in:
committed by
Alec Thomas
parent
2612dee604
commit
4065717136
@@ -19,8 +19,8 @@ var HTTP = internal.Register(httpBodyContentTypeLexer(MustNewLexer(
|
||||
},
|
||||
Rules{
|
||||
"root": {
|
||||
{`(GET|POST|PUT|DELETE|HEAD|OPTIONS|TRACE|PATCH|CONNECT)( +)([^ ]+)( +)(HTTP)(/)(1\.[01])(\r?\n|\Z)`, ByGroups(NameFunction, Text, NameNamespace, Text, KeywordReserved, Operator, LiteralNumber, Text), Push("headers")},
|
||||
{`(HTTP)(/)(1\.[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)(/)([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")},
|
||||
},
|
||||
"headers": {
|
||||
{`([^\s:]+)( *)(:)( *)([^\r\n]+)(\r?\n|\Z)`, EmitterFunc(httpHeaderBlock), nil},
|
||||
|
||||
@@ -55,7 +55,8 @@ func TestLexers(t *testing.T) {
|
||||
continue
|
||||
}
|
||||
|
||||
lexer := lexers.Get(strings.TrimSuffix(file.Name(), filepath.Ext(file.Name())))
|
||||
base := strings.Split(strings.TrimSuffix(file.Name(), filepath.Ext(file.Name())), "-")[0]
|
||||
lexer := lexers.Get(base)
|
||||
assert.NotNil(t, lexer)
|
||||
|
||||
filename := filepath.Join("testdata", file.Name())
|
||||
|
||||
5
lexers/testdata/http-2.actual
vendored
Normal file
5
lexers/testdata/http-2.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.expected
vendored
Normal file
27
lexers/testdata/http-2.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"}
|
||||
]
|
||||
Reference in New Issue
Block a user