From f1a0c2f1af178953d0f831a9c212395ed8a0faf7 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 4 Feb 2020 20:22:00 +0100 Subject: [PATCH] v2: parse optionals --- vlib/v/parser/fn.v | 2 +- vlib/v/parser/parse_type.v | 3 +++ vlib/v/parser/parser.v | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 2bc33f9c6c..aed31a0776 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -144,7 +144,7 @@ fn (p mut Parser) fn_decl() ast.FnDecl { p.check(.rpar) // Return 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() p.return_type = typ } diff --git a/vlib/v/parser/parse_type.v b/vlib/v/parser/parse_type.v index 8e6d3058d8..dc30b52ad5 100644 --- a/vlib/v/parser/parse_type.v +++ b/vlib/v/parser/parse_type.v @@ -84,6 +84,9 @@ pub fn (p mut Parser) parse_type() table.Type { p.next() p.check(.dot) } + if p.tok.kind == .question { + p.next() + } name := p.tok.lit match p.tok.kind { // func diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 35d01ec2d8..a4e4cce4a8 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -368,7 +368,7 @@ pub fn (p mut Parser) name_expr() (ast.Expr,table.Type) { p.next() p.check(.dot) } - else if p.tok.lit in ['strings'] { + else if p.tok.lit in ['strings', 'strconv'] { p.next() p.check(.dot) }