Beispiel #1
0
        public static LNode @case(LNode node, IMacroContext context)
        {
            LNode expr, braces = null;

            if (node.ArgCount == 2 && (braces = node.Args.Last).Calls(S.Braces) ||
                node.ArgCount == 1 && (node[0].Calls(S.Colon, 2) || node[0].Calls("'or", 2)))
            {
                expr = node[0];

                var results = LNode.List();
                while (expr.Calls("'or", 2))
                {
                    results.Add(LNode.Call(S.Case, LNode.List(expr[0]), expr[0]));
                    expr = expr[1];
                }
                if (braces != null)
                {
                    results.Add(LNode.Call(S.Case, LNode.List(expr), expr));
                    return(F.Call(S.Splice, results.Add(braces)));
                }
                else if (expr.Calls(S.Colon, 2))
                {
                    results.Add(LNode.Call(S.Case, LNode.List(expr[0]), expr[0]));
                    return(F.Call(S.Splice, results.Add(expr[1])));
                }
                else
                {
                    return(Les2.Reject(context, node, "Unrecognized syntax in case statement"));
                }
            }
            return(null);
        }
Beispiel #2
0
 public static LNode Var(LNode node, IMacroContext context)
 {
     if (node.ArgCount > 1)
     {
         return(null);
     }
     return(Les2.var(node, context));
 }
Beispiel #3
0
 public static LNode UsingDecl(LNode node, IMacroContext context)
 {
     if (node.ArgCount == 1)
     {
         if (Les2.IsComplexId(node.Args[0]))
         {
             // Looks like an import statement
             context.Warning(node.Target, "Use #import instead of #using.");
             return(node.WithTarget(S.Import));
         }
         var result = Les2.TranslateSpaceDefinition(node, context, S.Alias);
         if (result != null)
         {
             return(result.PlusAttr(F.Id(S.FilePrivate)));
         }
     }
     return(null);
 }
Beispiel #4
0
 public static LNode @namespace(LNode node, IMacroContext context)
 {
     return(Les2.TranslateSpaceDefinition(node, context, S.Namespace));
 }
Beispiel #5
0
 public static LNode Foreach(LNode node, IMacroContext context)
 {
     return(Les2.@foreach(node, context));
 }
Beispiel #6
0
 public static LNode For(LNode node, IMacroContext context)
 {
     return(node.ArgCount == 2 ? Les2.@for(node, context) : null);
 }
Beispiel #7
0
        public static LNode Prop(LNode node, IMacroContext context)
        {
            LNode visibility = node.Target;

            if (visibility.Name != sy__numprop)
            {
                node = node.PlusAttr(visibility);
            }

            {
                LNode     getExpr, init = null, name, tmp_12 = null, tmp_13 = null, tmp_14, tmp_15, type;
                LNodeList content;
                if (node.Args.Count == 2 && (tmp_12 = node.Args[0]) != null && tmp_12.Calls(CodeSymbols.Colon, 2) && (name = tmp_12.Args[0]) != null && (type = tmp_12.Args[1]) != null && node.Args[1].Calls(CodeSymbols.Braces) && (content = node.Args[1].Args).IsEmpty | true || node.Args.Count == 3 && (tmp_13 = node.Args[0]) != null && tmp_13.Calls(CodeSymbols.Colon, 2) && (name = tmp_13.Args[0]) != null && (type = tmp_13.Args[1]) != null && node.Args[1].Calls(CodeSymbols.Braces) && (content = node.Args[1].Args).IsEmpty | true && node.Args[2].Calls((Symbol)"#initially", 1) && (init = node.Args[2].Args[0]) != null)
                {
                    LNode args    = GetArgList(ref name);
                    var   newBody = LNode.List();
                    foreach (var part_ in content)
                    {
                        LNode part = part_;
                        {
                            LNode body, value;
                            if (part.Calls((Symbol)"#get", 0))
                            {
                                part = LNode.Id(S.get, part);
                            }
                            else if (part.Calls((Symbol)"#get", 1) && (body = part.Args[0]) != null)
                            {
                                part = part.WithName(S.get);
                                if (body.Calls(S.Braces))
                                {
                                    part = part.SetBaseStyle(NodeStyle.Special);
                                }
                                else
                                {
                                    part = part.With(S.Lambda, part.Target, body);
                                }
                            }
                            else if (part.Calls((Symbol)"#set", 0))
                            {
                                part = LNode.Id(S.set, part);
                            }
                            else if (part.Calls((Symbol)"#set", 1) && (body = part.Args[0]) != null)
                            {
                                part = part.WithName(S.set);
                                if (body.Calls(S.Braces))
                                {
                                    part = part.SetBaseStyle(NodeStyle.Special);
                                }
                                else
                                {
                                    part = part.With(S.Lambda, part.Target, body);
                                }
                            }
                            else if (part.Calls((Symbol)"#init", 1) && (value = part.Args[0]) != null)
                            {
                                init = value;
                                part = null;
                            }
                        }
                        if (part != null)
                        {
                            newBody.Add(part);
                        }
                    }
                    if (init != null)
                    {
                        if (newBody.IsEmpty)
                        {
                            newBody.Add(F.Id(S.get));
                        }
                        return(node.With(S.Property, type, name, args, F.Braces(newBody), init));
                    }
                    else
                    {
                        return(node.With(S.Property, type, name, args, F.Braces(newBody)));
                    }
                }
                else if (node.Args.Count == 1 && (tmp_14 = node.Args[0]) != null && tmp_14.Calls(CodeSymbols.Colon, 2) && (name = tmp_14.Args[0]) != null && (tmp_15 = tmp_14.Args[1]) != null && tmp_15.Calls(CodeSymbols.Lambda, 2) && (type = tmp_15.Args[0]) != null && (getExpr = tmp_15.Args[1]) != null)
                {
                    var args = GetArgList(ref name);
                    return(node.With(S.Property, type, name, args, getExpr));
                }
            }
            return(Les2.Reject(context, node, "Unrecognized property syntax"));

            LNode GetArgList(ref LNode name_apos)
            {
                if (name_apos.Calls(S.IndexBracks))
                {
                    var args = name_apos.Args.RemoveAt(0);
                    name_apos = name_apos[0].PlusAttrs(name_apos.Attrs);
                    return(F.Call(S.AltList, args));
                }
                else
                {
                    return(LNode.Missing);
                }
            }
        }
Beispiel #8
0
 public static LNode Cons(LNode node, IMacroContext context)
 {
     return(Les2.FnOrCons(node, context, true));
 }
Beispiel #9
0
 public static LNode Fn(LNode node, IMacroContext context)
 {
     return(Les2.FnOrCons(node, context, false));
 }
Beispiel #10
0
 public static LNode Alias(LNode node, IMacroContext context)
 {
     return(Les2.TranslateSpaceDefinition(node, context, S.Alias));
 }
Beispiel #11
0
 public static LNode Struct(LNode node, IMacroContext context)
 {
     return(Les2.TranslateSpaceDefinition(node, context, S.Struct));
 }