v2: parse optionals

pull/3652/head
Alexander Medvednikov 2020-02-04 20:22:00 +01:00
parent ac5c4e3203
commit f1a0c2f1af
3 changed files with 5 additions and 2 deletions

View File

@ -144,7 +144,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
p.check(.rpar) p.check(.rpar)
// Return type // Return type
mut typ := table.void_type mut typ := table.void_type
if p.tok.kind in [.name, .lpar, .amp, .lsbr] { if p.tok.kind in [.name, .lpar, .amp, .lsbr, .question] {
typ = p.parse_type() typ = p.parse_type()
p.return_type = typ p.return_type = typ
} }

View File

@ -84,6 +84,9 @@ pub fn (p mut Parser) parse_type() table.Type {
p.next() p.next()
p.check(.dot) p.check(.dot)
} }
if p.tok.kind == .question {
p.next()
}
name := p.tok.lit name := p.tok.lit
match p.tok.kind { match p.tok.kind {
// func // func

View File

@ -368,7 +368,7 @@ pub fn (p mut Parser) name_expr() (ast.Expr,table.Type) {
p.next() p.next()
p.check(.dot) p.check(.dot)
} }
else if p.tok.lit in ['strings'] { else if p.tok.lit in ['strings', 'strconv'] {
p.next() p.next()
p.check(.dot) p.check(.dot)
} }