/// <summary>
        /// 将该节点添加到父节点中
        /// </summary>
        /// <param name="faher"></param>
        /// <param name="node"></param>
        public override void AddChild(BEleme faher, BEleme node)
        {
            if ((node is JDefinitionEleme && (node as JDefinitionEleme).PVariableType == EVariableType.Definition) ||
                (node is JFunEleme && (node as JFunEleme).PVariableType == EVariableType.Definition)
                )
            {
                BEleme elme = faher;
                while (elme != null)
                {
                    if (IsFunOrPage(elme))
                    {
                        var rangeEleme = elme as RangeEleme;
                        if (rangeEleme.Variables == null)
                        {
                            rangeEleme.Variables = new SortedDictionary <string, BEleme>();
                        }

                        if (elme is JFunEleme)
                        {
                            node.AliasName = node.Name + "_" + this.PBParser.VarIndexCount++ + "_";
                        }
                        rangeEleme.Variables.Add(node.Name, node);
                        break;
                    }
                    elme = elme.Father;
                }
            }
            if (faher.Childs == null)
            {
                faher.Childs = new List <BEleme>();
            }

            faher.Childs.Add(node);
            node.Father = faher;
        }
        /// <summary>
        /// 获取名称是否存在
        /// </summary>
        /// <param name="node"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        private BEleme GetNameExists(BEleme node, string name, bool isFatherFind)
        {
            if (node == null)
            {
                return(null);
            }
            BEleme elme = node;

            while (elme != null)
            {
                if (IsFunOrPage(elme))
                {
                    var range = elme as RangeEleme;
                    if (range.Variables != null && range.Variables.ContainsKey(name))
                    {
                        return(range.Variables[name]);
                    }
                    if (!isFatherFind)
                    {
                        return(null);
                    }
                }
                elme = elme.Father;
            }

            return(null);
        }
Esempio n. 3
0
        /// <summary>
        /// 执行
        /// </summary>
        /// <param name="fileName"></param>
        public override void Eexc(string fileName)
        {
            var    bParser = this.CreateParser();
            BEleme b       = this.ExecBefore(fileName);

            if (b == null)
            {
                bParser.ReplaceCharLinePass = this.ReplaceCharLinePass;
                bParser.AnalysisFile((f) => {
                    this.Eexc(f);
                });
                var filePath = Path.Combine(this.Root, fileName);
                b = bParser.Execute(new ParserText()
                {
                    RootPath = this.Root,
                    Path     = filePath,
                    Content  = this.GetFileContent(filePath),
                    Type     = this.EType
                });
                if (b == null)
                {
                    return;
                }
            }
            AddData(fileName, b, bParser);
        }
Esempio n. 4
0
        public static void ElemeAllToString(this BEleme beleme, StringBuilder sbCode)
        {
            if (beleme == null || beleme.Childs.IsNull())
            {
                return;
            }

            var charaShow = false;

            if (beleme is JValueEleme)
            {
                var jv = beleme as JValueEleme;
                if (jv.Characteristic != null)
                {
                    charaShow = true;
                    sbCode.Append("__" + jv.Characteristic.GetMethodName() + "__(");
                }
            }
            foreach (var child in beleme.Childs)
            {
                sbCode.Append(child.ToCode());
                if (beleme is RangeEleme || beleme is IHChild || child is IHChild)
                {
                    continue;
                }


                child.ElemeAllToString(sbCode);
            }
            if (charaShow)
            {
                sbCode.Append(")");
            }
        }
        /// <summary>
        /// 验证变量是否存在
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public override BEleme ValidateNameExists(BEleme node, string name, bool isFatherFind)
        {
            if (SystemVar.Contains(name))
            {
                return new NoEleme()
                       {
                           Name = name
                       }
            }
            ;
            var tag = this.GetNameExists(node, name, isFatherFind);

            if (tag == null)
            {
                string fileValue = GetIncludeVar(name);

                if (fileValue != null)
                {
                    return new BEleme()
                           {
                               AliasName = fileValue
                           }
                }
                ;
            }
            return(tag);
        }
Esempio n. 6
0
 /// <summary>
 /// 添加类 属性值
 /// </summary>
 /// <param name="name"></param>
 /// <param name="eleme"></param>
 public void AddPropertyValue(string name, BEleme eleme)
 {
     if (PropertyValue == null)
     {
         this.PropertyValue = new SortedDictionary <string, BEleme>();
     }
     PropertyValue[name] = eleme;
 }
Esempio n. 7
0
        private void Finally()
        {
            var finallyE = new BEleme();

            finallyE.Father             = this.pTryEleme;
            this.pTryEleme.FinallyValue = finallyE;
            this.ValidChar('{');
            new JavaSciptSpan(this.PBParser, this.pTryEleme).Init();
            this.ValidChar('}');
        }
Esempio n. 8
0
 /// <summary>
 /// 获取别名
 /// </summary>
 /// <param name="eleme"></param>
 /// <returns></returns>
 public static string GetAliasName(this BEleme eleme)
 {
     if (!string.IsNullOrEmpty(eleme.AliasName))
     {
         return(eleme.AliasName);
     }
     else
     {
         return(eleme.Name);
     }
 }
Esempio n. 9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool Foreach()
        {
            this.SetUpPoint();
            string varName = string.Empty;

            this.GetTag();
            if (this._Tag == "var")
            {
                this.GetTagNotNull();
                varName = this._Tag;
            }
            else
            {
                varName = this._Tag;
            }

            this.GetTag();
            if (this._Tag != "in")
            {
                this.ResetUpPoint();
                return(false);
            }

            pFEleme            = new JForeachEleme();
            pFEleme.Father     = this.NEleme;
            pForeachEleme      = pFEleme as JForeachEleme;
            pForeachEleme.Name = varName + "_" + this.PBParser.VarIndexCount++ + "_";

            var def = new JDefinitionEleme();

            def.SetPoint(this.PBParser.Point);
            def.Name = varName;
            var exists = this.ValidateNameExists(varName);

            if (exists != null)
            {
                def.Name          = exists.GetAliasName();
                def.PVariableType = Entity.EVariableType.SetValue;
            }
            this.AddFather(def, new JConstEleme(pForeachEleme.Name, Entity.EValueType.Const));
            this.AddFather(pForeachEleme, def);

            var vE = new ValueEleme();

            vE.Father = this.NEleme;
            var vS = new ValueSpan(this.PBParser, vE);

            vS.Init();
            pForeachEleme.Where = vE;
            return(true);
        }
        public override void AddIncludeVar(string name, BEleme eleme, string fileName)
        {
            includeVars[name] = fileName;
            var pageEleme = this.PBParser.LumpElem as JPageEleme;

            if (pageEleme.IncludeVar == null)
            {
                pageEleme.IncludeVar = new SortedDictionary <string, BEleme>();
            }


            pageEleme.IncludeVar[name] = eleme;
            includeVars[name]          = fileName;
        }
Esempio n. 11
0
        /// <summary>
        /// 获取父类
        /// </summary>
        /// <param name="e"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static T GetFather <T>(this BEleme e) where T : class
        {
            var f = e;

            while (f != null)
            {
                if (f is T)
                {
                    return(f as T);
                }

                f = f.Father;
            }

            return(default(T));
        }
Esempio n. 12
0
        ///// <summary>
        ///// 内容
        ///// </summary>
        //private void Body() {
        //    foreach (var child in this._beleme.Childs) {
        //        sbCode.Append(child.ToString());
        //        this.ForChild(child);
        //        if (child.IsSetVar())
        //            sbCode.AppendLine(";");
        //    }
        //}

        /// <summary>
        /// 循环子节点
        /// </summary>
        /// <param name="b"></param>
        private void ForChild(BEleme b)
        {
            if (b.Childs.IsNull())
            {
                return;
            }
            foreach (var child in b.Childs)
            {
                //if (!child.IsHide)
                sbCode.Append(child.ToString());

                //this.ForChild(child);
                //this.SetElemEndChar(child);
                //if (child is DefinitionEleme)
                //   sbCode.AppendLine(";");
            }
        }
Esempio n. 13
0
        /// <summary>
        /// 分析注释
        /// </summary>
        /// <param name="eleme"></param>
        public void AnalysisAnnotation(BEleme eleme)
        {
            StringBuilder sbDesc;

            if (lineEnd.TryGetValue(this.PBParser.Point.Y - 1, out sbDesc))
            {
                if (!(eleme is DefinitionEleme || eleme is FunEleme))
                {
                    return;
                }

                LineAnnotation.Instance(this).Add(new LineAnnInfo()
                {
                    Desc  = sbDesc.ToString(),
                    Eleme = eleme
                });
            }
        }
Esempio n. 14
0
        /// <summary>
        /// 索引
        /// </summary>
        private void Index()
        {
Start:
            this.SetUpPoint();
            this.GetChar();
            BEleme elem = null;

            if (Tools.StrStartChars.Contains(this._Char))
            {
                elem = new JConstEleme("\"" + this.GetString(this._Char) + "\"", EValueType.Const);
            }
            else if (char.IsNumber(this._Char))
            {
                elem = new JConstEleme(this.GetIntString(), EValueType.Const);
            }
            else
            {
                this.ResetUpPoint();
                elem        = new JValueEleme();
                elem.Father = this.NEleme;
                var valueS = new ValueSpan(this.PBParser, elem);
                valueS.Init();
            }
            this.GetChar();
            switch (this._Char)
            {
            case ',':
                goto Start;

            case ']':
                var jIndex = new JIndexEleme();
                jIndex.IndexEleme        = elem;
                elem.Father              = jIndex;
                this.pVariableAttr.Index = jIndex;
                jIndex.Father            = this.NEleme;
                this.End(EPType.Index, jIndex);
                break;

            default:
                this.Error();
                break;
            }
        }
Esempio n. 15
0
        public void AddData(string fileName, BEleme value, BParser bParser)
        {
            lock (lockWrite) {
                if (Datas.ContainsKey(fileName) && this.IsStartUp)
                {
                    return;
                }

                Datas[fileName] = value;
                this.WriteFile(bParser, value, fileName);
            }

            if (!Datas.ContainsKey(fileName))
            {
                lock (lockWrite) {
                    if (!Datas.ContainsKey(fileName))
                    {
                        Datas[fileName] = value;
                        this.WriteFile(bParser, value, fileName);
                    }
                }
            }
        }
Esempio n. 16
0
 /// <summary>
 /// 将该节点添加到父节点中
 /// </summary>
 /// <param name="faher"></param>
 /// <param name="node"></param>
 public virtual void AddChild(BEleme faher, BEleme node)
 {
 }
Esempio n. 17
0
 public JavaSciptSpan(BParser parser, BEleme ele)
     : base(parser, ele)
 {
 }
Esempio n. 18
0
 public ValueSpan(BParser parser, BEleme ele)
     : base(parser, ele)
 {
 }
Esempio n. 19
0
 public DictionarySpan(BParser parser, BEleme ele)
     : base(parser, ele)
 {
 }
Esempio n. 20
0
 /// <summary>
 /// 添加被引用的变量
 /// </summary>
 /// <param name="name"></param>
 /// <param name="fileName"></param>
 public void AddIncludeVar(string name, BEleme eleme, string fileName)
 {
     this.PBParser.POperate.AddIncludeVar(name, eleme, fileName);
 }
Esempio n. 21
0
 /// <summary>
 /// 分析注释
 /// </summary>
 /// <param name="eleme"></param>
 public void AnalysisAnnotation(BEleme eleme)
 {
     this.PBParser.POperate.AnalysisAnnotation(eleme);
 }
Esempio n. 22
0
 public Span(BParser parser, BEleme ele)
 {
     this.PBParser = parser;
     this.NEleme   = ele;
 }
Esempio n. 23
0
 /// <summary>
 /// 将节点添加到父类节点中
 /// </summary>
 /// <param name="father"></param>
 /// <param name="node"></param>
 public void AddFather(BEleme father, BEleme node)
 {
     this.PBParser.POperate.AddChild(father, node);
 }
Esempio n. 24
0
 /// <summary>
 /// 验证变量是否存在
 /// </summary>
 /// <param name="node">节点</param>
 /// <param name="name">要查找的名称</param>
 /// <param name="isFatherFind">是否继续往父类查找</param>
 /// <returns></returns>
 public virtual BEleme ValidateNameExists(BEleme node, string name, bool isFatherFind)
 {
     return(null);
 }
Esempio n. 25
0
 /// <summary>
 /// 将节点添加到父类节点中
 /// </summary>
 /// <param name="node"></param>
 public void AddFather(BEleme node)
 {
     this.AddFather(this.NEleme, node);
 }
Esempio n. 26
0
 /// <summary>
 /// 添加被引用的变量
 /// </summary>
 /// <param name="name"></param>
 /// <param name="fileName"></param>
 public abstract void AddIncludeVar(string name, BEleme eleme, string fileName);
Esempio n. 27
0
        protected override void WriteFile(BParser bParser, BEleme b, string fileName)
        {
            var           parser      = bParser as JavaScriptCodeParser;
            var           csClassName = this.GetFileNameForCs(fileName);
            var           fs          = new FormatString(b);
            StringBuilder sbCode      = new StringBuilder();

            sbCode.AppendLine("using System;");
            sbCode.AppendLine("using Sys.JavaScript;");
            sbCode.AppendLine("using XZ.ParseLanguage.Types.JavaScripts;");
            sbCode.AppendLine("namespace " + this.CompileNameSpan + " {");
            sbCode.AppendLine("    public class " + csClassName + " : JsBase {");

            #region 包含文件
            string classVarName = string.Empty;
            if (parser.IncludeFile != null)
            {
                foreach (var inFile in parser.IncludeFile)
                {
                    classVarName = this.GetFileNameForCs(inFile);
                    sbCode.AppendLine(string.Format("    private {0} __{1}__ = new {0}();", classVarName, classVarName.SetFirstLower()));
                }
            }

            #endregion

            #region 定义全局变量
            var gvars = (b as RangeEleme).Variables;
            if (gvars != null)
            {
                foreach (var g in gvars.Values)
                {
                    if (g is JDefinitionEleme)
                    {
                        (g as JDefinitionEleme).PVariableType = EVariableType.SetValue;
                    }
                    else if (g is JFunEleme)
                    {
                        (g as JFunEleme).PVariableType = EVariableType.SetValue;
                    }

                    sbCode.AppendLine(string.Format("        public _U_ {0} = _U_.Undefined(); ", g.Name));
                }
            }
            #endregion

            sbCode.AppendLine("        public " + csClassName + "() { ");
            sbCode.Append(fs.ToString());
            sbCode.AppendLine("        }");
            sbCode.AppendLine("    }");
            sbCode.AppendLine("}");
            if (this.GetCompileText(fileName, sbCode.ToString()))
            {
                return;
            }
            string path = Path.Combine(this.WriteRoot, csClassName + ".cs");
            if (!Directory.Exists(Path.GetDirectoryName(path)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(path));
            }
            using (FileStream f = new FileStream(path, FileMode.Create, FileAccess.Write)) {
                StreamWriter sw = new StreamWriter(f);
                sw.Write(sbCode.ToString());
                sw.Dispose();
                sw.Close();
                f.Dispose();
                f.Close();
            }
        }
Esempio n. 28
0
 public NewSpan(BParser parser, BEleme ele)
     : base(parser, ele)
 {
 }
Esempio n. 29
0
 public FunctionSpan(BParser parser, BEleme ele)
     : base(parser, ele)
 {
 }
 public static bool IsFunOrPage(BEleme e)
 {
     return(e is JFunEleme || e is JPageEleme);
 }