c variadic calls
This commit is contained in:
@@ -889,11 +889,27 @@ parse_statement :: proc(parser: ^Parser) -> ast.Stmt_Id {
|
||||
return id
|
||||
}
|
||||
|
||||
parse_params :: proc(parser: ^Parser) -> []ast.Param {
|
||||
parse_params :: proc(parser: ^Parser) -> ([]ast.Param, bool) {
|
||||
params: [dynamic]ast.Param
|
||||
params.allocator = parser.module.allocator
|
||||
variadic := false
|
||||
skip_newlines(parser)
|
||||
for current(parser).kind != .Right_Paren && current(parser).kind != .Eof {
|
||||
if current(parser).kind == .Ellipsis {
|
||||
marker := advance(parser)
|
||||
if variadic {
|
||||
source.add(parser.diagnostics, marker.span, "duplicate variadic marker")
|
||||
}
|
||||
variadic = true
|
||||
skip_newlines(parser)
|
||||
if _, ok := allow(parser, .Comma); ok {
|
||||
skip_newlines(parser)
|
||||
}
|
||||
if current(parser).kind != .Right_Paren {
|
||||
source.add(parser.diagnostics, current(parser).span, "variadic marker must be the final parameter")
|
||||
}
|
||||
continue
|
||||
}
|
||||
names: [dynamic]token.Token
|
||||
names.allocator = parser.module.allocator
|
||||
for {
|
||||
@@ -923,7 +939,7 @@ parse_params :: proc(parser: ^Parser) -> []ast.Param {
|
||||
}
|
||||
break
|
||||
}
|
||||
return params[:]
|
||||
return params[:], variadic
|
||||
}
|
||||
|
||||
parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
|
||||
@@ -931,7 +947,7 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
|
||||
if _, ok := allow(parser, .Left_Paren); !ok {
|
||||
source.add(parser.diagnostics, current(parser).span, "expected '(' after 'func'")
|
||||
}
|
||||
params := parse_params(parser)
|
||||
params, variadic := parse_params(parser)
|
||||
if _, ok := allow(parser, .Right_Paren); !ok {
|
||||
source.add(parser.diagnostics, current(parser).span, "expected ')' after parameters")
|
||||
}
|
||||
@@ -954,6 +970,7 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
|
||||
file=parser.file,
|
||||
c_abi=c_abi,
|
||||
has_body=false,
|
||||
variadic=variadic,
|
||||
params=params,
|
||||
result=result,
|
||||
diagnostic=source.INVALID_DIAGNOSTIC,
|
||||
@@ -991,6 +1008,7 @@ parse_function :: proc(parser: ^Parser, name: token.Token, c_abi: bool) {
|
||||
file=parser.file,
|
||||
c_abi=c_abi,
|
||||
has_body=true,
|
||||
variadic=variadic,
|
||||
params=params,
|
||||
result=result,
|
||||
body=body[:],
|
||||
|
||||
Reference in New Issue
Block a user