Skip to content

Commit 48eb046

Browse files
committed
feat: improve ast
1 parent 7c8e804 commit 48eb046

5 files changed

Lines changed: 872 additions & 17 deletions

File tree

syntax/bash/lifter/lifter.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ func (l *Lifter) convert(node bast.Node) hast.Node {
4242
return &hast.Ident{Name: node.Name}
4343
case *bast.Word:
4444
return &hast.Ident{Name: node.Val}
45+
case *bast.FuncDecl:
46+
return l.convertFuncDecl(node)
47+
case *bast.AssignStmt:
48+
return l.convertAssignStmt(node)
4549
default:
4650
panic(fmt.Sprintf("unknown node type: %T", node))
4751
}
@@ -72,3 +76,21 @@ func (l *Lifter) convertCmdExpr(cmd *bast.CmdExpr) hast.Node {
7276
Recv: args,
7377
}
7478
}
79+
80+
func (l *Lifter) convertFuncDecl(decl *bast.FuncDecl) hast.Node {
81+
body := &hast.BlockStmt{}
82+
for _, stmt := range decl.Body.List {
83+
body.List = append(body.List, l.convert(stmt).(hast.Stmt))
84+
}
85+
return &hast.FuncDecl{
86+
Name: &hast.Ident{Name: decl.Name.Name},
87+
Body: body,
88+
}
89+
}
90+
91+
func (l *Lifter) convertAssignStmt(stmt *bast.AssignStmt) hast.Node {
92+
return &hast.AssignStmt{
93+
Lhs: l.convert(stmt.Lhs).(hast.Expr),
94+
Rhs: l.convert(stmt.Rhs).(hast.Expr),
95+
}
96+
}

syntax/hulo/ast/walk_test.go

6.47 KB
Binary file not shown.

0 commit comments

Comments
 (0)