From e0129662919d9a4076d92f75269524b6ad169d78 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 24 Mar 2020 15:44:17 +0100 Subject: [PATCH] parser/ast: Block --- vlib/v/ast/ast.v | 7 ++++++- vlib/v/parser/parser.v | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index cd5ead91fd..0d78a94270 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -19,7 +19,7 @@ ConcatExpr | Type | AsCast | TypeOf | StringInterLiteral pub type Stmt = GlobalDecl | FnDecl | Return | Module | Import | ExprStmt | ForStmt | StructDecl | ForCStmt | ForInStmt | CompIf | ConstDecl | Attr | BranchStmt | HashStmt | AssignStmt | EnumDecl | TypeDecl | DeferStmt | GotoLabel | GotoStmt | -LineComment | MultiLineComment | AssertStmt | UnsafeStmt | GoStmt +LineComment | MultiLineComment | AssertStmt | UnsafeStmt | GoStmt | Block // pub type Type = StructType | ArrayType // pub struct StructType { // fields []Field @@ -30,6 +30,11 @@ pub: typ table.Type } +pub struct Block { +pub: + stmts []Stmt +} + // | IncDecStmt k // Stand-alone expression in a statement list. pub struct ExprStmt { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d050c3a0ed..d5f2c39316 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -334,6 +334,12 @@ pub fn (p mut Parser) line_comment() ast.LineComment { pub fn (p mut Parser) stmt() ast.Stmt { match p.tok.kind { + .lcbr { + stmts := p.parse_block() + return ast.Block{ + stmts: stmts + } + } .key_assert { p.next() expr := p.expr(0)