Esempio n. 1
0
        public void ParseFile()
        {
            foreach (var v in file.Children)
            {
                if (v is Comment)
                {
                    Comment _v = v as Comment;

                    Append(_v.ToString().Replace("\r\n", ""));
                }
                else if (v is UsingDeclaration)
                {
                    UsingDeclaration _v        = v as UsingDeclaration;
                    string           usingname = Tools._getUsingFullName(v);
                    listUsing.Add(usingname);
                    Append("//<C#>using " + usingname + ";");
                }
                else if (v is UsingAliasDeclaration)
                {
                    string usingname = Tools._getUsingFullName(v);
                    string id        = Tools._getIdentifier(v);
                    listUsinAlias.Add(id, usingname);
                    Append("import " + id + "=" + usingname + ";");
                }
                else if (v is NewLineNode)
                {
                    AppendLine();
                }
                else if (v is NamespaceDeclaration)
                {
                    string names           = Tools._getFirstType(v);
                    string oldCurNameSpace = curNamespace;
                    if (string.IsNullOrEmpty(curNamespace))
                    {
                        curNamespace = names;
                    }
                    else
                    {
                        curNamespace += "." + names;
                    }
                    ParseNameSpace(names, v);
                    curNamespace = oldCurNameSpace;
                }
                else if (v is TypeDeclaration)
                {
                    var    cname    = Tools._getIdentifier(v);
                    string oldclass = curClassName;
                    ParseClass(cname, v);//处理完恢复一下当前classname
                    curClassName = oldclass;
                }
                else
                {
                    logger.LogError("not support file element:" + v.GetType() + "|" + v.NodeType + "|" + v.StartLocation.Line);
                }
            }
        }
Esempio n. 2
0
        void ParseNameSpaceSingle(string names, AstNode node, bool withDepthAdd)
        {
            foreach (var v in node.Children)
            {
                if (v is Comment)
                {
                    Append(v.ToString().Replace("\r\n", ""));
                }
                else if (v is SimpleType)
                {
                }
                else if (v is MemberType)
                {
                }
                else if (v is CSharpTokenNode)
                {
                    if (v.ToString() == "namespace")
                    {
                        if (curNamespace == names)
                        {
                            Append("module " + names);
                        }
                        else
                        {
                            Append("export module " + names);
                        }
                        break;
                    }
                    if (v.ToString() == "{")
                    {
                        Append("{");
                        space += 4;
                        break;
                    }
                    if (v.ToString() == "}")
                    {
                        space -= 4;
                        Append("}");
                        break;
                    }
                }

                else if (v is NewLineNode)
                {
                    AppendLine();
                }

                else if (v is NamespaceDeclaration)
                {
                    if (withDepthAdd == false)
                    {
                        break;
                    }
                    string snames          = Tools._getFirstType(v);
                    string oldCurNameSpace = curNamespace;
                    if (string.IsNullOrEmpty(curNamespace))
                    {
                        curNamespace = snames;
                    }
                    else
                    {
                        curNamespace += "." + snames;
                    }
                    ParseNameSpaceSingle(snames, v, true);
                    //ParseNameSpaceDelay(snames, v);
                    curNamespace = oldCurNameSpace;
                }
                else if (v is TypeDeclaration)
                {
                    string cname    = Tools._getIdentifier(v);
                    string oldclass = curClassName;
                    ParseClass(cname, v);
                    curClassName = oldclass;
                }

                else
                {
                    logger.LogError("not support namespace element:" + v.GetType().Name + "|" + v.NodeType + "|" + v.StartLocation.Line);
                }
            }
        }