コード例 #1
0
        public bool ParseScriptFiles()
        {
            bool retValue = true;

            foreach (FileInfo file in Path.GetFiles("*.js"))
            {
                MyLogger.Log("Parsing file " + file.FullName + ": " + Environment.NewLine);
                MyLogger.IncreaseIndent();
                if (false == ParseScriptFile(file) && true == retValue)
                {
                    MyLogger.Alert("First failure occured on file " + file.Name + ": " + Environment.NewLine);
                    retValue = false;
                }
                MyLogger.Log("Done parsing file " + file.Name + "." + Environment.NewLine);
                MyLogger.Log("Writing file " + file.Name + " as cpp." + Environment.NewLine);
                PrintDoxygenFile();
                MyLogger.Log("Done writing file " + file.Name + " as cpp." + Environment.NewLine);
                MyLogger.DecreaseIndent();
            }
            return(retValue);
        }
コード例 #2
0
        /*
         * <?xml version="1.0" encoding="UTF-8"?>
         * <ScriptExtensionGroup>
         * <ScriptExtension Name ="Alarm Object" Author="Anv" Version="0.1" HomePage ="None">
         *      <Script Name ="alarm.js" >
         * */
        protected void ParseScriptFile(FileInfo file)
        {
            using (StreamReader reader = new StreamReader(file.FullName))
            {
                string line;
                bool   klassFound   = false;
                bool   mute         = false;
                string comment      = @"^(/\*\*| \* | \*\/){1}.*$";
                string klass        = @"^\/\/\*class (.*) {.*$";
                string _namespace   = @"^\/\/\*namespace (.*) {.*$";
                string strpublic    = @"^//\*public:.*$";
                string strprotected = @"^//\*(protected|private):.*$";
                string function     = @"^function ([A-Za-z0-9_]+)\(.*$";
                string endClass     = @"^\/\/\*};$";

                // Instantiate the regular expression object.
                Regex  commentRegex    = new Regex(comment, RegexOptions.Multiline);
                Regex  klassRegex      = new Regex(klass, RegexOptions.Multiline);
                Regex  _namespaceRegex = new Regex(_namespace, RegexOptions.Multiline);
                Regex  publicRegex     = new Regex(strpublic, RegexOptions.Multiline);
                Regex  protectedRegex  = new Regex(strprotected, RegexOptions.Multiline);
                Regex  functionRegex   = new Regex(function, RegexOptions.Multiline);
                Regex  endClassRegex   = new Regex(endClass, RegexOptions.Multiline);
                string NameSpace       = null;

                if (true == FileNotBackedUp)
                {
                    description = new FileInfo(file.Directory + "/" + FileName);
                    if (description.Exists)
                    {
                        string dateFormatted = DateTime.Now.ToString().Replace('-', '.').Replace(':', '.');
                        string preBackup     = description.Name;
                        description.MoveTo(description.FullName + "." + dateFormatted + ".old");
                        MyLogger.Log("Taking backup of \"" + preBackup + "\" to \"" + description.Name + Environment.NewLine);
                    }
                    else
                    {
                        MyLogger.Log("Didn't find file " + description.Name + " in Directory " + description.Directory + "." + Environment.NewLine);
                    }
                    FileNotBackedUp = false;
                }

                while ((line = reader.ReadLine()) != null)
                {
                    // Do something with line
                    Match commentMatch = commentRegex.Match(line);
                    if (commentMatch.Success)
                    {
                        if (0 < store.Count && commentMatch.Groups[1].ToString().Contains("/**"))
                        {
                            MyLogger.Log("New start of comment received before clear of store.");
                            store.Clear();
                        }
                        store.Add(line);
                    }
                    Match NameSpaceMatch = _namespaceRegex.Match(line);
                    if (NameSpaceMatch.Success)
                    {
                        NameSpace = NameSpaceMatch.Groups[1].ToString();
                    }
                    Match klassMatch = klassRegex.Match(line);
                    if (klassMatch.Success)
                    {
                        if (false == klassFound)
                        {
                            MyLogger.Log("Namespace is: " + NameSpace);
                            PushScriptExtension(klassMatch.Groups[1].ToString(), file, NameSpace);
                            klassFound = true;
                        }
                        else
                        {
                            mute = true;
                        }
                    }
                    if (mute && endClassRegex.Match(line).Success)
                    {
                        mute = false;
                    }
                    Match publicMatch = publicRegex.Match(line);
                    if (publicMatch.Success && !mute)
                    {
                        isPublic = true;
                    }
                    Match protectedMatch = protectedRegex.Match(line);
                    if (protectedMatch.Success && !mute)
                    {
                        isPublic = false;
                    }
                    Match functionMatch = functionRegex.Match(line);
                    if (functionMatch.Success)
                    {
                        if (true == isPublic)
                        {
                            CreateMethod(line);
                        }
                        else
                        {
                            MyLogger.Log("Skipping description for function \"" + functionMatch.Groups[1] + "\"." + Environment.NewLine);
                        }
                        store.Clear();
                    }
                }
                if (true == klassFound)
                {
                    PopScriptExtension();
                }
                MyLogger.DecreaseIndent();
                MyLogger.Log("Done parsing file " + file.Name + Environment.NewLine);
            }
        }