internal void ScanClassBody(LNodeList body) { foreach (var stmt in body) { int?i; { LNode altName; LNodeList attrs, childBody = default(LNodeList), parts, rest; if ((attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 3) && stmt.Args[0].IsIdNamed((Symbol)"alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true || (attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 4) && stmt.Args[0].IsIdNamed((Symbol)"alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true && stmt.Args[3].Calls(CodeSymbols.Braces) && (childBody = stmt.Args[3].Args).IsEmpty | true) { LNode genericAltName = altName; if (altName.CallsMin(CodeSymbols.Of, 1)) { } else { if (_genericArgs.Count > 0) { genericAltName = LNode.Call(CodeSymbols.Of, LNode.List().Add(altName).AddRange(_genericArgs.ToVList())).SetStyle(NodeStyle.Operator); } } var child = new AltType(attrs, genericAltName, LNode.List(), this); child.AddParts(parts); child.ScanClassBody(childBody); _children.Add(child); } else if ((attrs = stmt.Attrs).IsEmpty | true && (i = attrs.FirstIndexWhere(a => a.IsIdNamed(__alt))) != null && stmt.CallsMin(CodeSymbols.Constructor, 3) && stmt.Args[1].IsIdNamed((Symbol)"#this") && stmt.Args[2].Calls(CodeSymbols.AltList) && (rest = new LNodeList(stmt.Args.Slice(3))).IsEmpty | true && rest.Count <= 1) { parts = stmt.Args[2].Args; attrs.RemoveAt(i.Value); _constructorAttrs.AddRange(attrs); if (rest.Count > 0 && rest[0].Calls(S.Braces)) { _extraConstrLogic.AddRange(rest[0].Args); } AddParts(parts); } else { _classBody.Add(stmt); } } } }
[LexicalMacro("e.g. alt class Tree<T> { alt Node(Tree<T> Left, Tree<T> Right); alt Leaf(T Value); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; RVList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new RVList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, new RVList<LNode>(output)); } } return null; }
public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, LNode.List(output)); } } return null; }
[LexicalMacro("e.g. alt class Pair<A,B> { alt this(A Item1, B Item2); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class. " + "All data members are read-only, and for each member (e.g. Item1 and Item2 above), " + "a With() method is generated to let users create modified versions.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList<LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList<LNode>(); adt.GenerateOutput(ref output); return LNode.Call(CodeSymbols.Splice, LNode.List(output)); } } return null; }
public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, LNode.List(output))); } } return(null); }
[LexicalMacro("e.g. alt class Pair<A,B> { alt this(A Item1, B Item2); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class. " + "All data members are read-only, and for each member (e.g. Item1 and Item2 above), " + "a With() method is generated to let users create modified versions.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; VList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new VList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, LNode.List(output))); } } return(null); }
[LexicalMacro("e.g. alt class Tree<T> { alt Node(Tree<T> Left, Tree<T> Right); alt Leaf(T Value); }", "Expands a short description of an 'algebraic data type' into a set of classes with a common base class.", "#class", Mode = MacroMode.Passive | MacroMode.Normal)] public static LNode AlgebraicDataType(LNode classDecl, IMacroContext context) { int i; { LNode baseName; RVList <LNode> attrs, baseTypes, body; if ((attrs = classDecl.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && classDecl.Calls(CodeSymbols.Class, 3) && (baseName = classDecl.Args[0]) != null && classDecl.Args[1].Calls(CodeSymbols.AltList) && classDecl.Args[2].Calls(CodeSymbols.Braces)) { baseTypes = classDecl.Args[1].Args; body = classDecl.Args[2].Args; attrs = attrs.RemoveAt(i); var adt = new AltType(attrs, baseName, baseTypes, null); adt.ScanClassBody(body); var output = new RVList <LNode>(); adt.GenerateOutput(ref output); return(LNode.Call(CodeSymbols.Splice, new RVList <LNode>(output))); } } return(null); }
public void ScanClassBody(RVList<LNode> body) { foreach (var stmt in body) { int i; { LNode altName; RVList<LNode> attrs, childBody = default(RVList<LNode>), parts, rest; if ((attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 3) && stmt.Args[0].IsIdNamed((Symbol) "alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true || (attrs = stmt.Attrs).IsEmpty | true && stmt.Calls(CodeSymbols.Fn, 4) && stmt.Args[0].IsIdNamed((Symbol) "alt") && (altName = stmt.Args[1]) != null && stmt.Args[2].Calls(CodeSymbols.AltList) && (parts = stmt.Args[2].Args).IsEmpty | true && stmt.Args[3].Calls(CodeSymbols.Braces) && (childBody = stmt.Args[3].Args).IsEmpty | true) { LNode genericAltName = altName; if (altName.CallsMin(CodeSymbols.Of, 1)) { } else if (_genericArgs.Count > 0) genericAltName = LNode.Call(CodeSymbols.Of, new RVList<LNode>().Add(altName).AddRange(_genericArgs)); var child = new AltType(attrs, genericAltName, LNode.List(), this); child.AddParts(parts); child.ScanClassBody(childBody); _children.Add(child); } else if ((attrs = stmt.Attrs).IsEmpty | true && (i = attrs.IndexWhere(a => a.IsIdNamed(__alt))) > -1 && stmt.CallsMin(CodeSymbols.Cons, 3) && stmt.Args[1].IsIdNamed((Symbol) "#this") && stmt.Args[2].Calls(CodeSymbols.AltList) && (rest = new RVList<LNode>(stmt.Args.Slice(3))).IsEmpty | true && rest.Count <= 1) { parts = stmt.Args[2].Args; attrs.RemoveAt(i); _constructorAttrs.AddRange(attrs); if (rest.Count > 0 && rest[0].Calls(S.Braces)) _extraConstrLogic.AddRange(rest[0].Args); AddParts(parts); } else _classBody.Add(stmt); } } }