From ca9fa6407f0b023c1bc3b31c0db53483db43afae Mon Sep 17 00:00:00 2001 From: Alexey Date: Thu, 27 Feb 2020 00:43:37 +0300 Subject: [PATCH] v2: distinguish public and private constants --- vlib/v/ast/ast.v | 1 + vlib/v/fmt/fmt.v | 3 +++ vlib/v/fmt/tests/simple_expected.vv | 4 ++++ vlib/v/fmt/tests/simple_input.vv | 4 ++++ vlib/v/parser/parser.v | 1 + 5 files changed, 13 insertions(+) diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index d14b11224d..6511c4fc8c 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -89,6 +89,7 @@ pub struct ConstDecl { pub: fields []Field exprs []Expr + is_pub bool } pub struct StructDecl { diff --git a/vlib/v/fmt/fmt.v b/vlib/v/fmt/fmt.v index 6ebc2e98e9..fa48120ceb 100644 --- a/vlib/v/fmt/fmt.v +++ b/vlib/v/fmt/fmt.v @@ -127,6 +127,9 @@ fn (f mut Fmt) stmt(node ast.Stmt) { } } ast.ConstDecl { + if it.is_pub { + f.write('pub ') + } f.writeln('const (') f.indent++ for i, field in it.fields { diff --git a/vlib/v/fmt/tests/simple_expected.vv b/vlib/v/fmt/tests/simple_expected.vv index a00db4400a..61424079b5 100644 --- a/vlib/v/fmt/tests/simple_expected.vv +++ b/vlib/v/fmt/tests/simple_expected.vv @@ -18,6 +18,10 @@ const ( pi = 3.14 ) +pub const ( + i_am_pub_const = true +) + struct User { name string age int diff --git a/vlib/v/fmt/tests/simple_input.vv b/vlib/v/fmt/tests/simple_input.vv index 61a42501ad..6e383e4637 100644 --- a/vlib/v/fmt/tests/simple_input.vv +++ b/vlib/v/fmt/tests/simple_input.vv @@ -19,6 +19,10 @@ const ( pi=3.14 ) +pub const ( +i_am_pub_const=true +) + struct User { name string age int diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index b0c5f7b6f0..f32dbf362b 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1369,6 +1369,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl { return ast.ConstDecl{ fields: fields exprs: exprs + is_pub: is_pub } }