diff --git a/ast.v b/ast.v index fb6bd4a..470a1f3 100644 --- a/ast.v +++ b/ast.v @@ -36,7 +36,14 @@ type Stmt = AssignStmt struct InvalidExpr {} -type Type = StructType | ArrayType | FuncType | InterfaceType | Ident | StarExpr | SelectorExpr +type Type = StructType + | ArrayType + | MapType + | FuncType + | InterfaceType + | Ident + | StarExpr + | SelectorExpr struct GoFile { name Ident @[json: 'Name'] @@ -78,6 +85,12 @@ struct ArrayType { elt Expr @[json: 'Elt'] } +struct MapType { + node_type_str string @[json: '_type'] + key Expr @[json: 'Key'] + val Expr @[json: 'Value'] +} + struct Ellipsis { node_type_str string @[json: '_type'] elt Ident @[json: 'Elt'] diff --git a/expr.v b/expr.v index 89d0bf5..414b6f7 100644 --- a/expr.v +++ b/expr.v @@ -142,6 +142,13 @@ fn (mut app App) array_type(node ArrayType) { } } +fn (mut app App) map_type(node MapType) { + app.gen('map[') + app.expr(node.key) + app.gen(']') + app.expr(node.val) +} + fn (mut app App) star_expr(node StarExpr) { app.gen('&') app.expr(node.x) diff --git a/main.v b/main.v index ef9e034..18517a1 100644 --- a/main.v +++ b/main.v @@ -59,6 +59,10 @@ fn (mut app App) typ(t Type) { app.array_type(t) // app.gen('[]${t.elt.name}') } + MapType { + app.map_type(t) + // app.gen('[]${t.elt.name}') + } StarExpr { // Skip & if receiver is mut if app.is_mut_recv { diff --git a/tests/var_struct_fields/var_struct_fields.go b/tests/var_struct_fields/var_struct_fields.go index 1fc7d67..2653088 100644 --- a/tests/var_struct_fields/var_struct_fields.go +++ b/tests/var_struct_fields/var_struct_fields.go @@ -3,6 +3,7 @@ package main type Ok struct { a int b string + m map[string]int } func main() { diff --git a/tests/var_struct_fields/var_struct_fields.vv b/tests/var_struct_fields/var_struct_fields.vv index a136a1d..df32310 100644 --- a/tests/var_struct_fields/var_struct_fields.vv +++ b/tests/var_struct_fields/var_struct_fields.vv @@ -4,6 +4,7 @@ struct Ok { pub mut: a isize b string + m map[string]int } fn main() {