v2: distinguish public and private constants

pull/3859/head
Alexey 2020-02-27 00:43:37 +03:00 committed by GitHub
parent 46ec400cb3
commit ca9fa6407f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 0 deletions

View File

@ -89,6 +89,7 @@ pub struct ConstDecl {
pub: pub:
fields []Field fields []Field
exprs []Expr exprs []Expr
is_pub bool
} }
pub struct StructDecl { pub struct StructDecl {

View File

@ -127,6 +127,9 @@ fn (f mut Fmt) stmt(node ast.Stmt) {
} }
} }
ast.ConstDecl { ast.ConstDecl {
if it.is_pub {
f.write('pub ')
}
f.writeln('const (') f.writeln('const (')
f.indent++ f.indent++
for i, field in it.fields { for i, field in it.fields {

View File

@ -18,6 +18,10 @@ const (
pi = 3.14 pi = 3.14
) )
pub const (
i_am_pub_const = true
)
struct User { struct User {
name string name string
age int age int

View File

@ -19,6 +19,10 @@ const (
pi=3.14 pi=3.14
) )
pub const (
i_am_pub_const=true
)
struct User { struct User {
name string name string
age int age int

View File

@ -1369,6 +1369,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
return ast.ConstDecl{ return ast.ConstDecl{
fields: fields fields: fields
exprs: exprs exprs: exprs
is_pub: is_pub
} }
} }