1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

v2: initial interface support; fix enum_hex_test.v

This commit is contained in:
Alexander Medvednikov
2020-03-31 19:59:38 +02:00
parent 50143ad9bf
commit 2b563bc69f
5 changed files with 92 additions and 46 deletions

View File

@@ -52,7 +52,7 @@ pub fn parse_stmt(text string, table &table.Table, scope &ast.Scope) ast.Stmt {
pref: &pref.Preferences{}
scope: scope
// scope: &ast.Scope{start_pos: 0, parent: 0}
}
p.init_parse_fns()
p.read_first_token()
@@ -71,13 +71,13 @@ pub fn parse_file(path string, table &table.Table, comments_mode scanner.Comment
table: table
file_name: path
pref: pref // &pref.Preferences{}
scope: &ast.Scope{
start_pos: 0
parent: 0
}
// comments_mode: comments_mode
}
p.read_first_token()
// p.scope = &ast.Scope{start_pos: p.tok.position(), parent: 0}
@@ -275,6 +275,9 @@ pub fn (p mut Parser) top_stmt() ast.Stmt {
.lsbr {
return p.attribute()
}
.key_interface {
return p.interface_decl()
}
.key_module {
return p.module_decl()
}
@@ -688,7 +691,7 @@ pub fn (p mut Parser) name_expr() ast.Expr {
p.expr_mod = ''
return ast.EnumVal{
enum_name: enum_name // lp.prepend_mod(enum_name)
val: val
pos: p.tok.position()
mod: mod
@@ -778,7 +781,7 @@ pub fn (p mut Parser) expr(precedence int) ast.Expr {
node = ast.SizeOf{
typ: sizeof_type
// type_name: type_name
}
}
.key_typeof {
@@ -1049,7 +1052,7 @@ fn (p mut Parser) infix_expr(left ast.Expr) ast.Expr {
left: left
right: right
// right_type: typ
op: op
pos: pos
}
@@ -1454,7 +1457,7 @@ fn (p mut Parser) const_decl() ast.ConstDecl {
fields << ast.Field{
name: name
// typ: typ
}
exprs << expr
// TODO: once consts are fixed reg here & update in checker
@@ -1581,6 +1584,28 @@ fn (p mut Parser) struct_decl() ast.StructDecl {
}
}
fn (p mut Parser) interface_decl() ast.InterfaceDecl {
is_pub := p.tok.kind == .key_pub
if is_pub {
p.next()
}
p.next() // `interface`
interface_name := p.check_name()
p.check(.lcbr)
for p.tok.kind != .rcbr && p.tok.kind != .eof {
line_nr := p.tok.line_nr
name := p.check_name()
p.fn_args()
if p.tok.kind == .name && p.tok.line_nr == line_nr {
p.parse_type()
}
}
p.check(.rcbr)
return ast.InterfaceDecl{
name: interface_name
}
}
fn (p mut Parser) return_stmt() ast.Return {
p.next()
// return expressions