mirror of
https://github.com/zeromicro/go-zero.git
synced 2026-05-08 07:30:01 +08:00
fix syntax of the key expression (#4586)
This commit is contained in:
@@ -545,7 +545,7 @@ func (p *Parser) parseAtDocGroupStmt() ast.AtDocStmt {
|
||||
}
|
||||
|
||||
stmt.Values = append(stmt.Values, expr)
|
||||
if p.notExpectPeekToken(token.RPAREN, token.KEY) {
|
||||
if p.notExpectPeekToken(token.RPAREN, token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -605,7 +605,7 @@ func (p *Parser) parseAtServerStmt() *ast.AtServerStmt {
|
||||
}
|
||||
|
||||
stmt.Values = append(stmt.Values, expr)
|
||||
if p.notExpectPeekToken(token.RPAREN, token.KEY) {
|
||||
if p.notExpectPeekToken(token.RPAREN, token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1115,7 +1115,7 @@ func (p *Parser) parseInfoStmt() *ast.InfoStmt {
|
||||
}
|
||||
|
||||
stmt.Values = append(stmt.Values, expr)
|
||||
if p.notExpectPeekToken(token.RPAREN, token.KEY) {
|
||||
if p.notExpectPeekToken(token.RPAREN, token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
@@ -1134,12 +1134,17 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
|
||||
var expr = &ast.KVExpr{}
|
||||
|
||||
// token IDENT
|
||||
if !p.advanceIfPeekTokenIs(token.KEY, token.RPAREN) {
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT, token.RPAREN) {
|
||||
return nil
|
||||
}
|
||||
|
||||
expr.Key = p.curTokenNode()
|
||||
|
||||
if !p.advanceIfPeekTokenIs(token.COLON) {
|
||||
return nil
|
||||
}
|
||||
expr.Colon = p.curTokenNode()
|
||||
|
||||
var valueTok token.Token
|
||||
var leadingCommentGroup ast.CommentGroup
|
||||
if p.notExpectPeekToken(token.QUO, token.DURATION, token.IDENT, token.INT, token.STRING) {
|
||||
@@ -1324,12 +1329,18 @@ func (p *Parser) parseKVExpression() *ast.KVExpr {
|
||||
var expr = &ast.KVExpr{}
|
||||
|
||||
// token IDENT
|
||||
if !p.advanceIfPeekTokenIs(token.KEY) {
|
||||
if !p.advanceIfPeekTokenIs(token.IDENT) {
|
||||
return nil
|
||||
}
|
||||
|
||||
expr.Key = p.curTokenNode()
|
||||
|
||||
// token COLON
|
||||
if !p.advanceIfPeekTokenIs(token.COLON) {
|
||||
return nil
|
||||
}
|
||||
expr.Colon = p.curTokenNode()
|
||||
|
||||
// token STRING
|
||||
if !p.advanceIfPeekTokenIs(token.STRING) {
|
||||
return nil
|
||||
|
||||
@@ -125,11 +125,11 @@ var infoTestAPI string
|
||||
func TestParser_Parse_infoStmt(t *testing.T) {
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
expected := map[string]string{
|
||||
"title:": `"type title here"`,
|
||||
"desc:": `"type desc here"`,
|
||||
"author:": `"type author here"`,
|
||||
"email:": `"type email here"`,
|
||||
"version:": `"type version here"`,
|
||||
"title": `"type title here"`,
|
||||
"desc": `"type desc here"`,
|
||||
"author": `"type author here"`,
|
||||
"email": `"type email here"`,
|
||||
"version": `"type version here"`,
|
||||
}
|
||||
p := New("foo.api", infoTestAPI)
|
||||
result := p.Parse()
|
||||
@@ -285,27 +285,27 @@ var atServerTestAPI string
|
||||
func TestParser_Parse_atServerStmt(t *testing.T) {
|
||||
t.Run("valid", func(t *testing.T) {
|
||||
var expectedData = map[string]string{
|
||||
"foo:": `bar`,
|
||||
"bar:": `baz`,
|
||||
"baz:": `foo`,
|
||||
"qux:": `/v1`,
|
||||
"quux:": `/v1/v2`,
|
||||
"middleware:": `M1,M2`,
|
||||
"timeout1:": "1h",
|
||||
"timeout2:": "10m",
|
||||
"timeout3:": "10s",
|
||||
"timeout4:": "10ms",
|
||||
"timeout5:": "10µs",
|
||||
"timeout6:": "10ns",
|
||||
"timeout7:": "1h10m10s10ms10µs10ns",
|
||||
"maxBytes:": `1024`,
|
||||
"prefix:": "/v1",
|
||||
"prefix1:": "/v1/v2_test/v2-beta",
|
||||
"prefix2:": "v1/v2_test/v2-beta",
|
||||
"prefix3:": "v1/v2_",
|
||||
"prefix4:": "a-b-c",
|
||||
"summary:": `"test"`,
|
||||
"key:": `"bar"`,
|
||||
"foo": `bar`,
|
||||
"bar": `baz`,
|
||||
"baz": `foo`,
|
||||
"qux": `/v1`,
|
||||
"quux": `/v1/v2`,
|
||||
"middleware": `M1,M2`,
|
||||
"timeout1": "1h",
|
||||
"timeout2": "10m",
|
||||
"timeout3": "10s",
|
||||
"timeout4": "10ms",
|
||||
"timeout5": "10µs",
|
||||
"timeout6": "10ns",
|
||||
"timeout7": "1h10m10s10ms10µs10ns",
|
||||
"maxBytes": `1024`,
|
||||
"prefix": "/v1",
|
||||
"prefix1": "/v1/v2_test/v2-beta",
|
||||
"prefix2": "v1/v2_test/v2-beta",
|
||||
"prefix3": "v1/v2_",
|
||||
"prefix4": "a-b-c",
|
||||
"summary": `"test"`,
|
||||
"key": `"bar"`,
|
||||
}
|
||||
|
||||
p := New("foo.api", atServerTestAPI)
|
||||
|
||||
@@ -151,13 +151,13 @@ service example {
|
||||
@doc (
|
||||
desc: "path demo"
|
||||
)
|
||||
@handler postPath
|
||||
post /example/path (PostPathReq) returns (PostPathResp)
|
||||
@handler getPath
|
||||
get /example/path (PostPathReq) returns (PostPathResp)
|
||||
}
|
||||
|
||||
@server (
|
||||
group: array
|
||||
prefix: /array
|
||||
group : array
|
||||
prefix : /array
|
||||
maxBytes: 1024
|
||||
)
|
||||
service example {
|
||||
|
||||
Reference in New Issue
Block a user