Example #1
0
func isNsDecl(node parser.Node) bool {
	if node.Type() != parser.NodeCall {
		return false
	}

	call := node.(*parser.CallNode)
	if call.Callee.(*parser.IdentNode).Ident != "ns" {
		return false
	}

	if len(call.Args) < 1 {
		return false
	}

	return true
}
Example #2
0
func nodeToStmt(node parser.Node) ast.Expr {
	switch node.Type() {
	case parser.NodeCall:
		return nodeFnCall(node.(*parser.CallNode))
	case parser.NodeString:
		return &ast.BasicLit{
			Kind:  token.STRING,
			Value: node.(*parser.StringNode).Value,
		}
	case parser.NodeIdent:
		return &ast.BasicLit{
			Kind:  token.STRING,
			Value: node.(*parser.IdentNode).Ident,
		}
	}
	panic(fmt.Sprintf("Unknow NodeType %v: %v", node.Type(), node))
}
Example #3
0
func nodeFnBody(node parser.Node) *ast.BlockStmt {
	stmt := ast.BlockStmt{
		List: make([]ast.Stmt, 1),
	}

	fmt.Println("=====\nNodeFnBody: %v=========\n", node)

	switch node.Type() {
	case parser.NodeCall:
		fmt.Printf("FnBody %+v %s", node, node.Type())

		exprstmt := &ast.ExprStmt{}
		exprstmt.X = nodeFnCall(node.(*parser.CallNode))
		stmt.List[0] = exprstmt

	default:
		panic(fmt.Sprintf("Doesn't support node: %v here", node))
	}

	return &stmt
}