Skip to content

Commit

Permalink
MapType
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Aug 26, 2024
1 parent 0db4179 commit 615c16f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ast.v
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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']
Expand Down
7 changes: 7 additions & 0 deletions expr.v
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions tests/var_struct_fields/var_struct_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
type Ok struct {
a int
b string
m map[string]int
}

func main() {
Expand Down
1 change: 1 addition & 0 deletions tests/var_struct_fields/var_struct_fields.vv
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ struct Ok {
pub mut:
a isize
b string
m map[string]int
}

fn main() {
Expand Down

0 comments on commit 615c16f

Please sign in to comment.