(goctl): fix prefix syntax (#4113)

This commit is contained in:
kesonan 2024-04-30 17:11:08 +08:00 committed by GitHub
parent 04116f647d
commit a9d27cda8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 37 additions and 5 deletions

View File

@ -1247,6 +1247,34 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
}
}
valueTok.Type = token.PATH
node := ast.NewTokenNode(valueTok)
node.SetLeadingCommentGroup(leadingCommentGroup)
expr.Value = node
return expr
} else if p.peekTokenIs(token.SUB) {
for {
if p.peekTokenIs(token.SUB) {
if !p.nextToken() {
return nil
}
subTok := p.curTok
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}
idTok := p.curTok
valueTok = token.Token{
Text: valueTok.Text + subTok.Text + idTok.Text,
Position: valueTok.Position,
}
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
} else {
break
}
}
valueTok.Type = token.PATH
node := ast.NewTokenNode(valueTok)
node.SetLeadingCommentGroup(leadingCommentGroup)

View File

@ -303,6 +303,7 @@ func TestParser_Parse_atServerStmt(t *testing.T) {
"prefix1:": "/v1/v2_test/v2-beta",
"prefix2:": "v1/v2_test/v2-beta",
"prefix3:": "v1/v2_",
"prefix4:": "a-b-c",
"summary:": `"test"`,
}

View File

@ -17,5 +17,6 @@
prefix1: /v1/v2_test/v2-beta
prefix2: v1/v2_test/v2-beta
prefix3: v1/v2_
prefix4: a-b-c
summary:"test"
)

View File

@ -180,12 +180,14 @@ service example {
post /example/array/base (DemoOfArrayReq) returns ([]string)
}
@server (
group: /prefix
prefix: foo-bar
summary: "test"
)
service example {
@handler nestDemo1
post /example/nest (NestDemoReq1) returns (NestDemoResp1)
@handler nestDemo2
post /example/nest2 (NestDemoReq2) returns (NestDemoResp2)
@handler prefixDemo
post /example/prefix (PostFormReq) returns (PostFormResp)
}
@server (