예제 #1
0
파일: WithMacro.cs 프로젝트: murven/Loyc
                      Mode = MacroMode.ProcessChildrenBefore)]   // post-normal-macro-expansion
        public static LNode with(LNode fn, IMessageSink sink)
        {
            LNode braces;

            if (fn.ArgCount != 2 || !(braces = fn.Args[1]).Calls(S.Braces))
            {
                return(null);
            }

            LNode         tmp   = F.Id(NextTempName());
            WList <LNode> stmts = braces.Args.ToWList();

            stmts = stmts.SmartSelect(stmt =>
                                      stmt.ReplaceRecursive(expr => {
                if (expr.Calls(S.Dot, 1))
                {
                    return(expr.WithArgs(new VList <LNode>(tmp, expr.Args.Last)));
                }
                return(null);
            }));
            stmts.Insert(0, F.Var(null, tmp.Name, fn.Args[0]));
            return(F.Braces(stmts.ToVList()));
        }
예제 #2
0
                      Mode = MacroMode.ProcessChildrenBefore)]   // post-normal-macro-expansion
        public static LNode with(LNode fn, IMacroContext context)
        {
            LNode braces;

            if (fn.ArgCount != 2 || !(braces = fn.Args[1]).Calls(S.Braces))
            {
                return(null);
            }

            LNode         tmp   = F.Id(NextTempName(context));
            WList <LNode> stmts = braces.Args.ToWList();

            stmts = stmts.SmartSelect(stmt =>
                                      stmt.ReplaceRecursive(expr => {
                if (expr.Calls(S.Dot, 1))
                {
                    return(expr.WithArgs(new VList <LNode>(tmp, expr.Args.Last)));
                }
                else if (expr.IsIdNamed("#"))
                {
                    return(tmp);
                }
                return(null);
            }));

            stmts.Insert(0, F.Var(null, tmp.Name, fn.Args[0]));
            if (IsExpressionContext(context))
            {
                stmts.Add(tmp);
                return(F.Call("#runSequence", stmts.ToVList()));
            }
            else
            {
                return(F.Braces(stmts.ToVList()));
            }
        }