private static void genWalkerVariants(GenContext ctx, NodeVariantsDecl variants, NodeVariantDecl variant) { ctx.Appendfnl("public virtual void walk{0}({1} __node)", variant.id, ToNs(ctx, variant.id)); ctx.Appendfnl("{{"); ctx.IncreaseIndent(); var nodeName = variant.id; var fields = variants.commonFieldsBefore.Concat(variant.fields).Concat(variants.commonFieldsAfter).ToList(); foreach (var field in fields) { genWalkerField(ctx, nodeName, field); } ctx.DecreaseIndent(); ctx.Appendfnl("}}"); }
private static void genExpectMethod(GenContext ctx, NodeVariantsDecl nodeVariantsDecl, NodeVariantDecl variant) { ctx.Appendfnl("public {0} Expect{1}()", ToNs(ctx, variant.id), variant.id); ctx.Appendfnl("{{"); ctx.IncreaseIndent(); { ctx.Appendfnl("return ({0})this;", ToNs(ctx, variant.id)); } ctx.DecreaseIndent(); ctx.Appendfnl("}}"); }
private static void genVariantNode(GenContext ctx, NodeVariantsDecl nodeVariantsDecl, NodeVariantDecl variant) { ctx.Appendfnl("public partial class {0} : {1}", variant.id, ToNs(ctx, nodeVariantsDecl.id)); ctx.Appendfnl("{{"); ctx.IncreaseIndent(); foreach (var field in variant.fields) { GenerateField(ctx, field); } foreach (var attr in variant.attributes) { ctx.Appendfnl("public {0} {1} {{ get; set; }}", attr.type, attr.id); } var fields = nodeVariantsDecl.commonFieldsBefore.Concat(variant.fields).Concat(nodeVariantsDecl.commonFieldsAfter).ToList(); { // default constructor ctx.Appendfnl("public {0}()", variant.id); ctx.Appendfnl("{{"); foreach (var field in fields) { ctx.IncreaseIndent(); if (field.many) { ctx.Appendfnl("this.{0} = new {1}();", field.id, FieldToCsharpType(ctx, field)); } ctx.DecreaseIndent(); } ctx.Appendfnl("}}"); } if (fields.Count > 0) { // constructor with parameters var fieldsArgs = fields.Select(x => string.Format("{0} {1}_p", FieldToCsharpType(ctx, x), x.id)); ctx.Appendfnl("public {0}({1})", variant.id, string.Join(", ", fieldsArgs)); ctx.Appendfnl("{{"); ctx.IncreaseIndent(); foreach (var field in fields) { var expr = field.id + "_p"; if (field.many) { expr = expr + " ?? new " + FieldToCsharpType(ctx, field) + "()"; } ctx.Appendfnl("this.{0} = {1};", field.id, expr); } ctx.DecreaseIndent(); ctx.Appendfnl("}}"); } genReplaceChildNode(ctx, fields); genToString(ctx, variant.id, fields, nodeVariantsDecl.attributes.Concat(variant.attributes).ToList()); ctx.DecreaseIndent(); ctx.Appendfnl("}}"); ctx.NewLine(); }
private NodeVariantDecl nodeVariant() { EnterRule_nodeVariant(); EnterRule("nodeVariant", 9); TraceIn("nodeVariant", 9); NodeVariantDecl r = default(NodeVariantDecl); IToken ID13 = default(IToken); List<FieldDecl> fields14 = default(List<FieldDecl>); List<AttributeDecl> attributes15 = default(List<AttributeDecl>); try { DebugEnterRule(GrammarFileName, "nodeVariant"); DebugLocation(76, 4); try { // ADL.g:77:5: ( ID OPEN ( fields )? CLOSE ( attributes )? ) DebugEnterAlt(1); // ADL.g:77:7: ID OPEN ( fields )? CLOSE ( attributes )? { DebugLocation(77, 7); ID13=(IToken)Match(input,ID,Follow._ID_in_nodeVariant458); DebugLocation(77, 10); Match(input,OPEN,Follow._OPEN_in_nodeVariant460); DebugLocation(77, 15); // ADL.g:77:15: ( fields )? int alt11=2; try { DebugEnterSubRule(11); try { DebugEnterDecision(11, false); int LA11_1 = input.LA(1); if ((LA11_1==ID)) { alt11 = 1; } } finally { DebugExitDecision(11); } switch (alt11) { case 1: DebugEnterAlt(1); // ADL.g:77:15: fields { DebugLocation(77, 15); PushFollow(Follow._fields_in_nodeVariant462); fields14=fields(); PopFollow(); } break; } } finally { DebugExitSubRule(11); } DebugLocation(77, 23); Match(input,CLOSE,Follow._CLOSE_in_nodeVariant465); DebugLocation(77, 29); // ADL.g:77:29: ( attributes )? int alt12=2; try { DebugEnterSubRule(12); try { DebugEnterDecision(12, false); int LA12_1 = input.LA(1); if ((LA12_1==ATTRIBUTES)) { alt12 = 1; } } finally { DebugExitDecision(12); } switch (alt12) { case 1: DebugEnterAlt(1); // ADL.g:77:29: attributes { DebugLocation(77, 29); PushFollow(Follow._attributes_in_nodeVariant467); attributes15=attributes(); PopFollow(); } break; } } finally { DebugExitSubRule(12); } DebugLocation(78, 4); r = new NodeVariantDecl { id = (ID13!=null?ID13.Text:default(string)), fields = fields14 ?? new List<FieldDecl>(), attributes = attributes15 ?? new List<AttributeDecl>() }; } } catch (RecognitionException re) { ReportError(re); Recover(input,re); } finally { TraceOut("nodeVariant", 9); LeaveRule("nodeVariant", 9); LeaveRule_nodeVariant(); } DebugLocation(83, 4); } finally { DebugExitRule(GrammarFileName, "nodeVariant"); } return r; }