Esempio n. 1
0
        protected string GenerateCode(Context ctx, Node node, string className)
        {
            bool        after = node.FindAttribute("after") != null;
            CodeBuilder sb    = new CodeBuilder();

            sb.Indent++;
            sb.AddLine("public class " + className + ": Rule");
            sb.BeginCurly();
            sb.AddLine(after ? "public override bool ApplyAfter(Context ctx, ref Node that)"
                                : "public override bool Apply(Context ctx, ref Node that)");

            sb.BeginCurly();
            sb.AddLine("Node cur = that;");
            var v = new List <Node>();

            node.GetTree(v);
            foreach (var item in v)
            {
                NCode code = item.Data as NCode;
                if (code == null)
                {
                    // sb.AddLine("//" + item.Data);
                }
                else
                {
                    sb.AddLine(code.Value);
                }
            }
            sb.AddLine("return false;");
            sb.End();
            sb.End();
            //sb.AddLine("}}");
            return(sb.ToString());
        }
Esempio n. 2
0
        public override bool Apply(Context ctx, ref Node that)
        {
            NCode code = that.Data as NCode;

            if (code != null && that.Items.Count > 0 &&
                (code.Value.IndexOf("$") > -1 || code.Value.IndexOf("#") > -1))
            {
                code.InsertChildren(that);
                that.Items.Clear();
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override bool ApplyAfter(Context ctx, ref Node that)
        {
            if (!that.Match("rule"))
            {
                return(false);
            }

            var    id        = that.FindAttribute("id");
            string className = id == null?ctx.GenName() : id.Second.Data as string;

            var   code = GenerateCode(ctx, that, className);
            NCode n    = new NCode(code);

            Node.Replace(ref that, new Node(n));
            return(true);
        }
Esempio n. 4
0
        protected string GenerateCode(Context ctx, string moduleName, Node node)
        {
            bool        after = node.Match("after");
            CodeBuilder sb    = new CodeBuilder();

            sb.AddLine("using System;");
            sb.AddLine("using akira;");
            sb.LineEnd();
            sb.AddLine("namespace akira." + moduleName);
            sb.BeginCurly();

            foreach (var item in node.Descendants)
            {
                NCode code = item.Data as NCode;
                if (code != null)
                {
                    sb.AddLine(code.Value);
                }
            }

            sb.End();

            return(sb.ToString());
        }